Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [python-2.x]

Python 2 is the predecessor of Python 3 and its last version, Python 2.7 was formally released on July 3, 2010. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 2 interpreter only. Do not mix this tag with the python-3.x tag.

Filter by
Sorted by
Tagged with
8
votes
2answers
249 views

Python 2.7 quiz

I made this quiz but the code seems to be really lengthy. Can anyone find a way to make my code shorter? Considerably shorter would be best but anything helps. I think the main problem is the ...
-4
votes
1answer
125 views

Python Code Classes Tkinter [closed]

I am learning to write my codes accordingly with functions and classes. My original code can create a graphic interface that interacts with different functions. As I said before, I am trying to write ...
6
votes
1answer
110 views

Command line noughts and crosses v2

I'm pretty new to Python - did some Fortran 77 at University for a minor project. Programming skills are a bit rusty! I plan to add a computer opponent next ... This is written in Python 2.7. <...
7
votes
1answer
97 views

A database of books, part 1

Backstory I collect books. A lot of books. Whitepapers, (programming) cookbooks, transcripts, important letters, overviews, you name it. Usually in PDF, otherwise my house would be too small. To ...
8
votes
1answer
159 views

DisjointSet class in Python

I would like to improve my DisjointSet class implementation in Python. I would be grateful for specific advice. I use it in online contests so it must be short, quick and reusable. ...
3
votes
0answers
381 views

PyCrypto AES-CFB with SCrypt and HMAC

I am brushing up on my Python, and since I would like to learn a bit about encryption, I figured I would give PyCrypto a try. I obviously wouldn't implement encryption in any production environment, ...
1
vote
0answers
603 views

Mersenne Prime Finder in Python

This program generates prime numbers: ...
1
vote
0answers
716 views

Constructing and printing a maze

I have implemented a maze with a function addCoordinate where x and y denote the x and y coord of grid and block type: zero means open and 1 means wall. a ...
2
votes
3answers
218 views

isPrime functions in Python and Java

This Python code looks messy to me. Am I doing any wrong style, or is this how Python looks like? ...
7
votes
1answer
97 views

Email processor for DMARC - Take in an email message, output DMARC-compliant message

NOTE: This is for Python 2.7 currently, NOT Python 3. There's some type of black magic at work for Content Disposition that doesn't properly work on Py3, so I have to fix that first before I have a ...
1
vote
1answer
523 views

Project RoboNest - Nestable/Breakable For Loops + Basic While Loops for Robot Framework

I'm implementing things in Robot Framework that it does not support by default, including nestable For Loops and, now, While Loops. I'm looking for readability, algorithm, methodology, and/or ...
4
votes
1answer
542 views

Genomic Range Query in Python

Recently, I worked on one of the Codility Training - Genomic Range Query (please refer to one of the evaluation report for the detail of the task. The solution in Python is based on prefix sum, and ...
3
votes
2answers
2k views

Python battleship program (2 player or 1 player)

I recently started studying python with a much heavier study regimen, I wanted someone to review my code to see what they thought. I do have a to do list at the start of the code so any tips on how I ...
11
votes
3answers
3k views

Removing entries from a dictionary containing bad words

I have a dictionary with each item containing a quote in another dictionary: ...
11
votes
1answer
4k views

Farthest point algorithm in Python

I am learning Python and I tried to do a program to find K points from a set of N points, farthest as much as possible (I'm not ...
6
votes
1answer
242 views

Printing bowTie pattern in efficient and pythonic way

I've posted code/library to GitHub for first time over here. The code is pretty simple. It generates a BowTie pattern of given size and characters. I did attempt to implement DP by calculating only ...
10
votes
4answers
1k views

Accepting user input for tickets and tips

I've done tutorials as well as searches. I need assistance in simplifying this code. Please don't do it for me- instead inform me of what, where and why you are trying to simplify or write less code. ...
2
votes
0answers
465 views

Python scapy subnet mapper

This a follow-up question of Python scapy - TCP port scan of subnet I've decided to make an all powerful subnet mapper in Scapy to better understand how tools like ...
2
votes
1answer
6k views

Computing the powerset of a list

I've written the following code for computing the powerset of a list (we consider the list has all distinct elements, although it doesn't really matter). Can this function be further optimized? <...
3
votes
2answers
2k views

Create all possible character combinations of any size

I am trying to create all possible character combinations of a given word. For example, “laptop” will include the following possible combinations: ...
1
vote
1answer
238 views

Greedy Algorithm - Tuple Comparator

I've completed the problem set 9 of the OCW 6.00sc course which requires the implementation of a greedy algorithm - see prompt. When completing problem 2, it is asked to implement comparator ...
3
votes
1answer
391 views

Iterative binary search

I have made a simple binary search algorithm with the assumptions that the input array is sorted and has only unique values. ...
3
votes
2answers
2k views

Calculate True Positive, False Positive, True Negative and False negative and colourize output

Objective : Calculate True Positive, False Positive, True Negative and False negative and colourize the image accordignly, based on ground-truth and prediction from my classifier model. Problem : ...
4
votes
1answer
1k views

Python scapy - TCP port scan of subnet

Question I love using NMAP and other related tools to scan networks really fast. But using a tool and understanding how it works are 2 different things, thus I tried creating a program where I can ...
2
votes
0answers
659 views

Optimization Resource File for Robot Framework

I'm looking for optimization between these files, and simplification. If something already exists to do what I have a keyword do, I'd like to know about it. Loops.py is located in one of my other ...
1
vote
2answers
567 views

Find count of alternating numbers

What I am trying to do is to find count of alternating numbers such that it alternates with -ve and positive sign for e.g.: 1 -2 3 -4 would get me 4 3 2 1 as from 1 to -4 including the two numbers ...
5
votes
0answers
180 views

Code for training machine learning linear regression and SVM

Ok , for my final year project I've wrote this piece of code to train my machine learning model on a this dataset , here the code i used ...
1
vote
2answers
338 views

Read n lines, and count the lines that do not contain the string “CD”

I would like to know how to improve the execution speed of the code below. The context : n is an integer read from the stdin, and represents the number of cases. Each case is represented by a ...
2
votes
0answers
321 views

Python2.7 Some xor fun

After doing the Cryptopals challanges, which I found scrolling through codereview, and finally being able to solve set1 challenge 6. I decided to have a little xor fun, and make an automated xor ...
3
votes
2answers
2k views

Reversing substrings in parentheses

Problem: The task is to reverse the strings contained in each pair of matching parentheses, starting from the innermost pair. The results string should not contain any parentheses. Example: ...
3
votes
2answers
924 views

Python image encryption security analysis

I'm currently seeking someone to review the source code for an image encryption program in Python 2.7. The code is complete and should run provided you have installed the correct packages. For this ...
2
votes
2answers
4k views

Finding an increasing sequence from a given array in a time-efficient manner in Python

Problem Statement: Given a sequence of integers as an array, we have to determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the ...
5
votes
1answer
146 views

Collating list of dicts to table format

I've got a list of dicts, data, that updates periodically and is persisted to a database. Every time data is updated, the gui ...
3
votes
2answers
581 views

Merging the frequency rankings of boys' names and girls' names

Problem statement: The html pages for each year which represents the top 1000 most common Girl and Boy names in the order of their frequency are ranked and provided. And they are ranked based on the ...
4
votes
1answer
12k views

Removing key/value pairs in list of dicts

I have a list of dicts that all have the same keys. If a key's value is None in all dicts then I want to remove them (A solution that creates a new dict is fine as ...
3
votes
1answer
54 views

Streamlining series of try-except + if-statements for faster loop processing in Python

I'm processing strings using regexes in a bunch of files in a directory. To each line in a file, I apply a series of try-statements to match a pattern and if they do, then I transform the input. After ...
5
votes
3answers
1k views

Beginner Tic Tac Toe game in Python

I've just started learning python and I tried making a tic tac toe game and would really appreciate it if I got some feedback. I know, my code isn't the best optimized but this is what I could come up ...
2
votes
2answers
428 views

Compare two files and save the result into a pickle file

My code should compare two vectors saved as dictionary (two pickle files) and save the result into a pickle file too. This works but very slowly. For one compare result I'm waiting about 7:20 min. ...
3
votes
1answer
291 views

TapeEquilibrium Codility implementation not achieving 100%

Given the following task description from here : A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P &...
5
votes
2answers
564 views

Prime Number Generator (6n + 1 or 6n - 1)

This generator is like most where it brute forces an integer: it see whether the integer is divisible by any of the primes; if so, then it's not a prime and vice versa. This though only compares ...
8
votes
3answers
2k views

Replacing English words in a string with their Spanish equivalents by dictionary lookup

I want to improve my code's performance and running time, looking for write my loops better. For example, I have a dictionary that contains words as keys, and their translation in Spanish as values. ...
5
votes
1answer
93 views

Saving web search results for EANs to CSV

This is my first program in Python. Following code is taken from different posts (mostly this site) and combined together so that I can automate my routine task. It's working properly but I need ...
8
votes
3answers
2k views

Function to censor single word in a sentence

The following function censors a single word of choice in a sentence with asterisks, regardless of how many times the word appears. How can I further simplify this code? ...
6
votes
2answers
5k views

Implementation of Sieve of Eratosthenes in Python

The following is my implementation of Sieve of Eratosthenes. Can somebody please review it? Am I adhering to the algorithm and is it a reasonable implementation of it? ...
1
vote
1answer
1k views

Python selenium object repository

I was trying to create the selenium web element object repository in python. I have come up with three ways to do so. However, I am new to python so I am not sure which one is better than other. ...
0
votes
2answers
9k views

Invoking functions using a function pointer approach [closed]

I re-used this answer from this StackOverflow answer to simulate a function pointer approach available in high-level languages like C. While using this approach in Python, the dictionary I am ...
6
votes
1answer
580 views

Python 2.7 Tower of Hanoi game with ASCII graphics

The game generates a fixed, "animated" game board via ASCII characters that is reprinted and cleared after each valid move. The format of the input for making moves is described in the script. You ...
5
votes
1answer
175 views

AIO programming challenge - Friendlist - Who has the most friends?

I attempted this sample question from the Australia Infomatics Competition. TL;DR - Each line of input contains two numbers, representing a mutual friendship relationship. The output needs to be the ...
2
votes
1answer
331 views

Load data in sqlite

I have written small application for inserting data into sqlite. can you please review. create data from specified path create Table into sqlite database Path format /user/proj/file ...
3
votes
5answers
115 views

Product iteration while checking for overlaps

This is an extended question to the following question I posted Class scheduling tool with image output Context of previous question: I have a multilayered dictionary that contains information ...