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
5
votes
1answer
14k 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
60 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
509 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
345 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
650 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
96 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
3k 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
12k 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 ...
7
votes
1answer
650 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
194 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
372 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
117 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 ...
3
votes
1answer
455 views

Using os.path.join in Python

I want to reduce/shorten this part quite a lot. If you see that a method can be reduced or even erased please do not hesitate to suggest that. Any answer that rescue the code would be great. ...
6
votes
1answer
134 views

Simple application in Python using OpenCV for face

I have been working on a simple Python application for face recognition with OpenCV. My code does its work and gets the job done, but I'm wondering if there's a 'better' way to do this. I hope I can ...
5
votes
3answers
1k views

WV lottery tool in Python

I am self taught in python. I love to play the lottery and play with numbers. I put this program together as a hobby to learn python and build something that people can use. I used and reused code ...
4
votes
2answers
139 views

File's encryption tool in terminal

I've created a wrapper for the SimpleCrypt library that allows to easily encrypt/decrypt a string. The application is used this : ...
6
votes
3answers
234 views

Class scheduling tool with image output

I have a multilayered dictionary that contains information about classes. I am using this to code an automatic schedule builder that I will eventually add to a separate Tkinter application I made that ...
4
votes
1answer
503 views

Console Tic Tac Toe

So I started Python this week, and I never programmed a game before. Even though Tic Tac Toe is probably the simplest game ever, I had some challenges while coding the game rules. I split my project ...
7
votes
1answer
201 views

Dynamic Programming with Project Euler problem 67

I am a beginner with python and programming in general. I started teaching myself about 2 months ago. I've been working my way through Project Euler and a few similar sites to build my chops, and ...
1
vote
3answers
1k views

Simple Blackjack game in Python 2.6.9

Like the title says, I made a very simple game of Blackjack using Python version 2.6.9. I am relatively new to python and programming so I would really appreciate some constructive criticism to help ...
3
votes
1answer
175 views

My images have secrets A.K.A. the making of aesthetic passwords V.2

This is my implementation of a prng steganography tool written in Python. You can also find the code on GitHub. Steganography is the art of hiding messages in (images, videos or even audio) I've ...
8
votes
2answers
7k views

Python code that compares two files byte by byte

I wrote a Python (2.7) script that compares a file byte by byte. filecmp was not suitable for the application because it compares metadata as well. How can I ...
14
votes
1answer
19k views

Decorator to measure execution time of a function

This decorator adds the elapsed time to a function's attributes when applied. My concerns: Is the code pythonic? Could this code be useful? Should I just use the ...
1
vote
0answers
270 views

Cellular Automata: Counting preimages

One of the Google Foobar challenges requires you to write a program to count the the number of preimages of a position in a 2D cellular automaton, under the following rules: You find that the ...
2
votes
1answer
251 views

Reverse shell allows connection between computers

I've recently made a reverse-shell which allows you remote shell access to other computers. It's written in Python 2 and it is cross-platform. Basically, it get's user input for a command and sends ...
25
votes
4answers
14k views

Validating Credit Card Numbers

This is one of the puzzles I was trying to solve, where the question is to validate the credit card number with following characteristics: It must contain exactly 16 digits. It must start ...
13
votes
2answers
538 views

A classy DNA nucleobase counter

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see Counting nucleobases in a nucleotide c. The repository with all my up-to-date solutions ...
3
votes
1answer
1k views

Download and write ~100k images

Currently I will be downloading around ~100K images. This process may run on a weekly basis, I'm considering the following factors: HTTP Requests (Will be taken care by external LB, so same source IP ...
4
votes
1answer
2k views

Splitting up a list with datetimes

I have this ordered list of datetimes that comprises of 30 minute slots: ...
4
votes
2answers
533 views

Encoding and Decoding In Python

My script encodes text and outputs random strings. It is different each time and loads a dictionary that has been pre-set by my dictionary gen.py (included after the main script). I've started my ...
4
votes
3answers
754 views

Simple RSS to HTML converter

Is this code pythonic, easy to read, stable, or missing something? ...
9
votes
3answers
4k views

Dictionary of dictionary - Get 2nd keys

I have a dictionary of dictionary such as d below, and I would like to get the list of all keys but not on the first level (i.e. ...
8
votes
3answers
27k views

Downloading images from URLs

I'm just beginning with Python and programming, so been trying to get as much experience reading code as possible. The script mentioned below do grab images from URLs and put them in into a folder. ...
5
votes
1answer
138 views

Using NumPy to scale data in 2 out of 3 columns

The below code takes a csv containing age, weight, height and prints the betas determined through linear regression to an output csv. It runs for 10 iterations using a different alpha for each, and ...
2
votes
2answers
11k views

Using BFS to solve 8-puzzle game using Python 2

I'm trying to solve the 8-puzzle game using BFS, DFS and A* algorithms implemented using Python 2.7. For now, I have managed to solve a couple of test cases using BFS and I want to know how I can ...
7
votes
1answer
1k views

Black Jack Game in Python (Jupyter)

I am working on Jupyter Notebook and I am new to Python. I have created this BlackJack Game (This is my 2nd Project as I am Learning Python. See my 1st - Tic Tac Toe ...
5
votes
1answer
331 views

First time using Tkinter

This is my first time using Tkinter and really trying to get use to using classes in Python. I wonder if I'm using self entirely too much, but here is my code: ...
3
votes
2answers
6k views

Text based survival game

I have recently made a text based survival game. I hope that I can improve the game but I am not sure where I can improve it. It is NOT EASY, don't expect to get over it the first time. ...
15
votes
3answers
808 views

My images have secrets A.K.A. the making of aesthetic passwords

This is my implementation of a prng steganography tool written in Python. You can also find the code on GitHub. Steganography is the art of hiding messages in (images, videos or even audio) I've ...
2
votes
0answers
41 views

Algorithm for point distribution of traversal between 2 points on a line in time

Not sure if this is best SO forum to post at, please suggest/move to more appropriate place otherwise. A synopsis of the problem 1st: Given a scenario where we have messages with data that define a ...
4
votes
1answer
236 views

Aggregating text and deleting duplicates with pandas to consolidate a table for reporting

At work, I use software for analyzing administrative data and daily I generate a CSV that looks like: ...
4
votes
1answer
1k views

Implement a boto3 RDS generator in Python

Boto3 does not seem to implement a generator for RDS instances, instead offering a marker and pagination feature. This code does work for my use case and I have been using it for the entire day ...
7
votes
1answer
3k views

Tic Tac Toe in Python (Jupyter)

I am working on Jupyter Notebook and I am new to Python. I have created this tic tac toe game. ...
14
votes
4answers
2k views

Codechef: Prime Number Generator

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! Input The input begins with the number t of test cases ...
6
votes
0answers
323 views

Simple AR Tag classifier

I have been working on creating a simple AR Tag classifier, for detecting a simple AR Tag glyph. Spitting out an image that looks like this: With the red circle indicating the corner closest to the ...
7
votes
2answers
562 views

Recursive function and memorization to find minimum operations to transform n to 1

I'm a new, self-taught programmer working on the Google FooBar challenge. I've submitted my answer (code at bottom) and it was accepted, but I'd like suggestions on how to improve my solution. ...

1
3 4
5
6 7
25