Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
4
votes
1answer
49 views
Parse text file function
This method takes a text file of my work schedule and parses it. It works, but is kind of kludgey, and I'm looking for feedback and suggestions. My first attempt at a file parser, and my first look ...
2
votes
2answers
55 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
1answer
20 views
Try to implement comments tree for django
I tried to create implementation of 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.
...
5
votes
1answer
105 views
Wedding Photography Cost Calculator
This is my first code. I would really appreciate a critique for it, if anyone can spare the time.
...
4
votes
1answer
79 views
My second Python script: an Instagram bot
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
1answer
64 views
Optimization/speed up of reduction function
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 ...
0
votes
1answer
36 views
Update a field in a list of dictionaries
I have a piece of code which follows this form. Is this correct or is there a better way?
...
2
votes
3answers
110 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: ...
13
votes
4answers
1k 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. ...
6
votes
1answer
206 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 ...
14
votes
1answer
132 views
Python - Minesweeper
I'm new to Python (and generally to programming), and I have recently written this Minesweeper game:
...
4
votes
2answers
33 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
76 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.
...
3
votes
1answer
31 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
65 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 ...
3
votes
1answer
146 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
83 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
33 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
43 views
1
vote
0answers
35 views
Wrapper for database queries [closed]
I had a written code in Python, which works with a database and selects information. Every function in my class creates a session and executes some queries (their quantity varies). Also, each such ...
1
vote
0answers
23 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
34 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
163 views
Text-based adventure game with combat and game-reset functionality
Please suggest improvements/refactoring to this game to make it more idiomatic Python.
...
3
votes
2answers
61 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 ...
2
votes
0answers
47 views
Linux-based WiFi AP daemon [closed]
I've written this small Linux-based daemon to create a WiFi AP that should work across various distros like Ubuntu, Fedora, etc.
I'm not a great expert in Python, nor do I know that the various ...
4
votes
0answers
56 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
112 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 ...
5
votes
2answers
109 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 ...
1
vote
1answer
34 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
120 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
94 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 ...
6
votes
2answers
756 views
Does this one-line text-based terrain generator go against standards?
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 ...
0
votes
1answer
107 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) ...
4
votes
1answer
57 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 ...
6
votes
1answer
51 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 ...
4
votes
2answers
274 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.
...
3
votes
2answers
83 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 ...
7
votes
3answers
227 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.
...
0
votes
1answer
32 views
Counting Calls in Python [closed]
The problem is as follows:
Design a function that generates the number of steps in the Collatz Conjecture
For more information
Essentially, for a given number, the sequence begins reducing the ...
4
votes
1answer
65 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 ...
6
votes
2answers
149 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.
...
7
votes
3answers
158 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 ...
2
votes
2answers
99 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 ...
1
vote
3answers
61 views
Optimization and accepted paradigms
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 ...
3
votes
1answer
75 views
Converting JDBC to CSV
One of my first ever jython scripts lets me get comma-separated values out of an RDBMS. I submit it here in hopes that you'll rip me apart. Without further ado, have at it:
...
0
votes
1answer
41 views
For and if loops in Python math game [closed]
I'm trying to get my program to iterate through a loop after a person gets the correct answers to the first question. I feel like there is a better way to do things syntactically.
...
4
votes
2answers
139 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
52 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
52 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
63 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 ...