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
3
votes
2answers
405 views

Comparing two partition functions in Python

I have written a partition function in Python (my_partition_adv). I have written this one after reading a similar function from a website. The version of the ...
4
votes
2answers
235 views

Thrice nested “OS” in Python

This Python main is what greets the user to a thrice nested super duper barebones OS. The entire rest of my code isn't bug free but this section is, and it feels dirty anyway. I'd like to know how ...
7
votes
2answers
1k views

How random is this password-generating algorithm?

This code's sole purpose is to create a very random password, using letters and numbers. I think that it fulfills its purpose, but I wonder, could it be done better? I'm not talking about efficiency,...
3
votes
1answer
730 views

Project Euler 39: Integer right triangles

I just finished Project Euler 39: If p is the perimeter of a right angle triangle with integral length sides, {a, b, c} … For which value of p ≤ 1000, is the number of solutions maximised? I'm ...
4
votes
3answers
2k views

Python Barcode Generator

I was asked to provide some example code for a job interview and didn't have anything to offer, so wrote the following function. A barcode generator may seem a bit basic, but there's some logic ...
6
votes
2answers
1k views

More elegant way to round decimals in Python?

I am working with currencies, and so have been using the decimal module to rule out any floating point weirdness in the following maths. I have to add together a number of decimal amounts, find an ...
1
vote
1answer
73 views

Avoiding use of .encode() in rss2html

My concern with this code is the excessive use of .encode('utf-8'). Any advice on refining these functions would be very helpful. rss2html GitHub repo ...
8
votes
4answers
2k views

Plague Inc. in Python - Extremely Early Stage

I've been working to create a game in Python similar to Plague Inc. and instead of just writing one big clump of code and then getting it reviewed, I wanted to do it stage-by-stage and make it a ...
11
votes
2answers
765 views

“FIZZ BANG BUZZ!” 3,7,11 efficiency

I wrote a fizz buzz variation method in Python which prints "fizz", "bang", and "buzz" for 3, 7, and 11 respectively. ...
17
votes
2answers
946 views

Given a page of content, determine shortest snippet containing all search phrases (no order required)

A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me ...
3
votes
1answer
86 views

Loop cleanly through different classes

If I have a number of different classes which manage certain tests. At the moment I have to launch each test individually which results in a lot of if statements. ...
14
votes
3answers
65k views

Splitting a list by indexes

I am trying to build an efficient function for splitting a list of any size by any given number of indices. This method works and it took me a few hours to get it right (I hate how easy it is to get ...
11
votes
1answer
2k views

Mafia game simulation engine

I've written a program to simulate a game of Mafia among several bots. Here's the directory structure the program lives in (to make understanding parts of the program easier): ...
7
votes
2answers
2k views

Python Email Program

I've written this email program in Python, and I would like to get some feedback on it. (i.e. closing the server twice after the raw input, etc.) ...
8
votes
3answers
2k views

2-player in a Python hangman game

This is a follow-up: Python Hangman Program I'm working on adding a few features to my hangman game, and I just implemented two-player gameplay, in the form of one player chooses the word to be ...
5
votes
4answers
188 views

Comparing phone numbers across CSVs Python

(continuation from Speeding up and fixing phone numbers from CSVs with Regex) I'm pulling all of the phone numbers from all CSVs in two different directories, outputting them in a single simple ...
2
votes
2answers
753 views

Speeding up and fixing phone numbers from CSVs with Regex

I've hodgepodged together an attempt to extract all phone numbers from all CSVs in a directory, regardless of where they are and what format they're in. I want all phone numbers to be printed to a ...
5
votes
1answer
2k views

Raspberry Pi LED for new emails

I'm learning how to use Python with the Raspberry Pi. I successfully followed the tutorial for how to have a Python script run on the Pi to check for new email and turn on an LED if any new messages ...
6
votes
5answers
2k views

Guessing Game in Python

Now that I've got this working, any improvements that I can make to better my code review would be helpful. ...
2
votes
1answer
191 views

Scraping thefreedictionary.com

This scrapes results from thefreedictionary.com: ...
5
votes
1answer
2k views

Strongly connected components algorithm

In my Python application, I am using Tarjan's algorithm to compute strongly connected components. Unfortunately, it shows up under profiling as one of the top functions in my application (at least ...
8
votes
2answers
95 views

Comparing Server Version Number History

I have this code that compares all version numbers of servers. (The version numbers are stored in an XML file) Before the code would compare the current version number with the previous. This caused ...
9
votes
3answers
1k views

Rendition of Project Euler 26 - reciprocal cycles

This is my solution for problem 26 from Project Euler: ...
11
votes
2answers
21k views

Dice-rolling simulator

I know there is a better way to store data. What is the most concise way to simplify this script? ...
0
votes
1answer
63 views

Dealing with a dirty table

I have to deal with a really ugly looking response I get back from a particular device. The string represents a table. Each section of the string represents the form: ...
5
votes
2answers
910 views

Numbers to Text Program - Python Training

I have written a numbers to text challenge for some people in my organisation to practice their Python skills. I am an economist working with pandas, but I am trying to teach them some stuff about ...
5
votes
1answer
666 views

Ping Pong Pi - A Ping Pong score and serving manager

I have spent a few hours on this code, but think it could be improved a bit. It requires eSpeak to be installed to run the speech synthesis, but the voice can be toggled on or off using the ...
9
votes
3answers
349 views

Use up all characters to form words

Task: Given a dictionary of words, and a set of characters, judge if all the characters can form the words from the dictionary, without any characters left. For example, given the dictionary {...
5
votes
2answers
267 views

Best way to display big data [closed]

I would like to display this data, callable at any time, but I'm not sure if this is the best practice to do so. ...
7
votes
1answer
130 views

Creating an object in Python with lots of long arguments [closed]

See the proposed changes in this Pull Request under def add_talk. ...
11
votes
2answers
583 views

Virtual machine using RPython and PyPy

I'm writing a virtual machine in Python using RPython and the PyPy toolchain. The RPython will still work in the ordinary Python 2 interpreter; it's just a bit slow unless it's compiled to C code with ...
1
vote
1answer
78 views

Script scraper for outputting variables and functions to a text file

I've been programming with Python 2.7 for about six months now and if possible, I'd like some critique to see what I might have done better or what I might be doing wrong. My objective was to make a ...
8
votes
3answers
34k views

Streamlined for-loop for comparing two lists [closed]

I'm new to Python and I'm wondering is there a way to streamline this clunky code I've written. Maybe a built-in function I've never come across before? I run through two lists of binary numbers and ...
1
vote
1answer
705 views

Depth first search, use of global variables, and correctness of time

As I was coding this algorithm I found that some variables that are meant to be global behave as they are intended to behave, but others do not. Specifically, my boolean arrays, e.g. ...
8
votes
2answers
3k views

Barnes-Hut n-body quadtree

Here's an attempt I've made of implementing the Barnes-Hut n-body algorithm, or its initial stage - The quadtree. That there're lots of lengthy doc strings might excuse the lack of detailed ...
5
votes
1answer
540 views

Fallout-style homework game

I've been going through LPHW (learn Python the hard way) lessons and I am now at exercise No36 where I have to create a similar game. Could you please review it and point out beginner mistakes? <...
5
votes
1answer
894 views

Improving a triangulation test script

I am a relative beginner to Python and as such I've been working on little things here and there in the office that strike me as something interesting that might be fun to try and code a solution. ...
7
votes
2answers
11k views

Python Hangman program

To learn Python, I've been working through Learn Python the Hard Way, and to exercise my Python skills I wrote a little Python Hangman game (PyHangman - creative, right?): ...
1
vote
0answers
680 views

Optimize Python script for memory which opens and reads multiple times the same files

I have code that works perfectly, but it uses too much memory. Essentially this code takes an input file (lets call it an index, that is 2 column tab-separated) that searches in a second input file (...
-1
votes
1answer
661 views

Use of multiple value errors in Python [closed]

Review this code. ...
4
votes
1answer
10k views

Copy a directory structure to another, but only copying specific files

script.py: ...
0
votes
1answer
2k views

Upload document to mongodb

Simple post and download web app in Bottle: server.py ...
3
votes
1answer
132 views

Is it a good style to run external commands in Python? [closed]

I have lots of external shell commands to run. So I gave every command a name and then run it. ...
3
votes
1answer
3k views

Simple in-memory database

How can I improve this code (elegance, best practices, etc)? ...
9
votes
2answers
3k views

Long constructors, inheritance, class method constructors

My class takes functions as a parameter. There are 6 of them, along with numerous other parameters. Almost all of the fields have default values. It also has a class method that creates an instance ...
10
votes
1answer
181 views

Shortcuts and imports for large RPG basic code

I decided to work on putting together an Arena-style (very basic) text-based RPG as a way to help myself learn Python. Unfortunately, after about 1,000 lines of pieced-together code, I realize that I'...
4
votes
1answer
253 views

Paragraph Matching in Python

So I developed some code as part of a larger project. I came upon a problem with how to match paragraphs, and wasn't sure how to proceed, so I asked on Stack Overflow here. You can find an in-depth ...
13
votes
1answer
6k views

Faster computation of barycentric coordinates for many points

I'm just starting to understand the Python syntax and I created a module that does what I wanted, but really slow. Here are the stats of cProfile, top 10 ordered by ...
3
votes
1answer
633 views

Making this Pygame code object-oriented [closed]

PYTHON 2.7- I want to make my code OOP. I also want feedback from you on correctness, tidiness, design patterns and so on. Here's the download link. It's not permanent but it's the best I have ...
8
votes
3answers
15k views

Model cars as classes

I am learning about object oriented programming in Python using classes. I have attached an image of what I had in mind when structuring my classes. This is supposed script model cars. I want to know ...