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
4
votes
2answers
559 views

Basic Brainfuck interpreter (part 2)

I have this obsession with esoteric programming languages. So I decided to spiff up my previous Brainfuck interpreter. ...
2
votes
0answers
58 views

Microcast algorithm

Following is the main file in the project (executing tasks). It uses the mpi4py module, and multiple processes execute the same code. Please review the code and ...
3
votes
1answer
659 views

Try to implement comments tree for Django

I've tried to create an implementation of a tree for comments. I want use it in Django to store comments. Please tell me how to implement it much simpler, without recursion, to find child nodes. <...
6
votes
1answer
186 views

Wedding Photography Cost Calculator

This is my first code. I would really appreciate a critique for it, if anyone can spare the time. ...
6
votes
1answer
13k views

Instagram bot script

I'm very new to Python and would like some feedback on my script. I'm fairly clueless to best practices, code correctness etc. so if there's anything at all that looks wrong, isn't 'pythonic' or could ...
3
votes
2answers
422 views

Reduction function in Rainbow tables implementation

I'm working on an implementation of Rainbow tables as part of a project. I understand the main principles behind it had have a working solution. Unfortunately the reduction function portion of my ...
-1
votes
1answer
59 views

Update a field in a list of dictionaries [closed]

I have a piece of code which follows this form. Is this correct or is there a better way? ...
3
votes
3answers
169 views

A simple prompt-and-print program

I have accomplished what I wanted to do but I think this can be done better. I want my code to look professional. What my code does is ask for your name and gives output in below form. Input: ...
23
votes
5answers
25k views

Simple random number generator

I have been wanting to learn programming for some time now and decided to really give it a shot today. I have edited and read lots of things in Java to fix small issues but never written from scratch. ...
7
votes
1answer
506 views

Basic BrainFuck interpreter

I was bored, so I wrote a BrainFuck interpreter in Python. It essentially takes input for the amount of cells, then parses the inputted code through a series of if ...
23
votes
1answer
6k views

Python - Minesweeper

I'm new to Python (and generally to programming), and I have recently written this Minesweeper game: ...
4
votes
2answers
181 views

List Comprehension in Pythonic answer to LPTHW ex48

I'm not really seeing any use for a generator here, unless there's some way to hook a generator into a language dictionary. But in the following code, the longhand version of the ...
4
votes
2answers
3k views

Getting the unique factors of a number recursively

I have written the below code to get the unique factors. Please offer suggestions for better results. ...
5
votes
1answer
97 views

Connected components algorithm does not scale past 10,000 nodes

I found a connected components algorithm posted here on SO and modified it for my own purposes. It runs well for small input sets, but doesn't scale as well as I would like. The largest set I've ...
5
votes
1answer
3k views

Moving the player across an ASCII art “world”

Wow, this one is definitely going to need some improvement. So, just for fun, I decided to make a program where the player moves across a 2-dimensional ASCII-art map. If the player types something ...
6
votes
1answer
546 views

Moving a rover and receiving current coordinates

I made a little text-based game where you move a rover and it gives you the current coordinates. You can essentially move around a 1000x1000 grid, and get output into ...
2
votes
1answer
141 views

Painting Fences - optimize for faster performance

I am attempting this problem at Codeforces. I'm stuck as it gives a time limit exceeded error for large inputs though the logic I followed is similar to that of the editorial. I'd be grateful for any ...
0
votes
1answer
88 views

Using Comprehensions to Handle a Large Dataset in Python 2.7

I have a Python 2.7.6 script parsing large files (~60MB to ~2GB) containing lines of the following format: componentA componentB < floating point value > My goal is to sum the floating point ...
1
vote
1answer
5k views

Convert 2D list to dict of list of index

I have a 2D list like this: ...
1
vote
0answers
649 views

Optimizing Recursive Quadtree

I have a written a quadtree program in Python 2.7 to cross-correlate large catalogs with each other i.e. find the common objects in the catalogs based on their position. The problem is that it's still ...
2
votes
1answer
95 views

Is this Python pathfinder efficient enough?

I'd like to see if my code follows common practice, or is already efficient or fast enough. ...
5
votes
2answers
5k views

Text-based adventure game with combat and game-reset functionality

Please suggest improvements/refactoring to this game to make it more idiomatic Python. ...
6
votes
2answers
208 views

Text-based terrain generator (Part 2)

I've updated my text-based terrain generator a lot. Even though I haven't worked on it all that much. I really just want to know, like usual, is there anything I can improve? How can I shorten the ...
10
votes
1answer
578 views

Decoding custom packets with Python using Twisted

This server require fast decoding of packets from clients, as I am expecting 5000 concurrent clients that is sending packets possibly every second. This is a game server (5000 players walking send ...
-1
votes
3answers
177 views

Better sorting speed

import sys x=int(sys.stdin.readline()) lst = [int(sys.stdin.readline()) for i in xrange(x)] lst.sort() print lst How can I make this code faster for large ...
6
votes
2answers
5k views

Processing large file in Python

I have some code that calculates the "sentiment" of a Tweet. The task starts with an AFINN file, that is a tab-separated list of around 2500 key-value pairs. I read this into a ...
0
votes
1answer
61 views

Variable creation and returning Boolean values

Out of a challenge for myself, I created this little program in which you can create "variables", test those "variable" values, test regular values, or clear all the "variables". ...
10
votes
3answers
159 views

Saving player name throughout script-launches

I would like to use this in a program to save users' names even after they relaunch the script. I was just wondering if there were some ways I could clean up this code. Note: this currently was made ...
3
votes
3answers
657 views

Apple picking game. More efficient method than using global variables

I have been working on a small game called apple picker, it's text-based, and relvolves around picking and selling apples. Unfortunately I've been using global variables for this whole thing and it's ...
4
votes
2answers
825 views

Does this one-line text-based terrain generator go against standards? [closed]

This isn't really much of an actual project, just something I threw together in about 5-10 minutes. I just want to know if it goes with the current Python standards, and if anything should be changed ...
1
vote
1answer
2k views

A small backup script in Python

I work on ubuntu machine and my backup requirements are straightforward. My only requirement is the usual copy paste, but only changed files (ie. the files whose modification-time OR size has changed) ...
5
votes
1answer
2k views

Persistent key value store for Python using SQLite3

This is a module to implement a key value store in Python using SQLite3. Originally written to allow sharing of configuration among multiple threads that are already sharing a SQLite3 database, I have ...
7
votes
1answer
3k views

Refactoring Tkinter GUI that reads from and updates csv files, and opens E-Run files

Background My lab administers four computer programs in three separate appointments. At each appointment, the subject does the programs in a pseudo-randomized order. Also, three of the programs have ...
5
votes
2answers
13k views

Manipulating filenames using Python

I was tasked with creating a script to be able to rename some files and then move them into different folders based on a code in the filename. ...
4
votes
2answers
743 views

Word counter script

I made a word counter. It works as long as there aren't any lone punctuation marks. How could it be improved? (Could it be made simpler? Are the comments detailed/clear enough? etc.) I know it's ...
10
votes
3answers
3k views

Saving high scores in a pickle database

Seeking to improve upon my high score 'module' code. It saves users' high score in a pickle database and if needed prints out the current scores in the database. ...
3
votes
1answer
6k views

Fast loop to create an array of values [closed]

I have a code that creates a 3D array of values from a minimum to a maximum in X and Z with constant Y. Right now I make it in normal Python, and then I transform it in a ...
4
votes
1answer
180 views

Checking for Prime Numbers [closed]

def is_prime(n): if n % 2 == 0 and n > 2: return False return all(n % i for i in xrange(3, int(math.sqrt(n)) + 1, 2)) The code works fine for a ...
9
votes
1answer
3k views

Z-Algorithm for pattern matching in strings

I was trying to refactor the following Python code (keeping the same time-complexity) which is an implementation of Z-Algorithm for pattern matching in strings. ...
9
votes
3answers
2k views

Script for finding cheating students in a quiz

Below is a script to find cheating students in a quiz in a daily moodle activity log exported in .xls. It works fine and is written in a procedural way. Essentially the script isolates the activity ...
4
votes
2answers
6k views

Simple Card Game in Python

After finishing up finals, I wasn't really working on coding for a while. I decided to write a card game to get back into the programming scene. I'm just wondering if there's anything that I missed ...
2
votes
3answers
115 views

Reading, cleaning and parsing CSV

This project was completed as part of an interview challenge. The feedback I received was: The code is neither optimized nor does it follow generally accepted paradigms, naming conventions or best ...
8
votes
2answers
30k views

K-means clustering in Python

The following code uses scikit-learn to carry out K-means clustering where \$K = 4\$, on an example related to wine marketing from the book DataSmart. That book uses excel but I wanted to learn Python ...
4
votes
2answers
366 views

Efficient use of regular expression and string manipulation

The following is my solution to Java vs C++. I think the way I have used the re library is inefficient, and possible erroneous as I am getting tle. ...
1
vote
0answers
179 views

A class with a function pointer instead of a generator

I am building TiKZ files, one pdf for each image I have. The purpose is to add text to each separately. The images are legion, so I created a script to generate the text files instead of generating ...
5
votes
4answers
5k views

Number Of Matching Elements In Two Lists

I have many sets of 2 strings. I'm trying to determine the number of matching elements in these 2 strings. The rules are if the strings share a common letter, that's a point, order does matter, but ...
4
votes
2answers
4k views

Chain of responsibility pattern

...
3
votes
1answer
4k views

Implementing command pattern in Python

I did some study on the command pattern but most of its examples were in Java so, there must be some difference in implementation in Python. I implemented it in Python with some minor differences, ...
4
votes
1answer
884 views

Searching a dictionary of words using difflib

I am trying to write a spellchecker and I wanted to use difflib to implement it. Basically I have a list of technical terms that I added to the standard Unix dictionary (...
4
votes
1answer
16k views

Extracting the text of a specific XML node

I have to extract friendlyName from the XML document. Here's my current solution: ...