Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
6
votes
2answers
138 views
Project Euler Problem 12 in Python
I'm trying to do Project Euler Problem 12, which reads as:
The sequence of triangle numbers is generated by adding the natural
numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 ...
2
votes
2answers
39 views
Bubble sort a list of integers for a number of iterations
I wrote a program for this problem, but it stopped because it took too much time. Any tips?
The Problem:
Bubble sort is the simplest algorithm for elements sorting. At each iteration we sequentially ...
4
votes
3answers
143 views
Stack Implementation in Python
I have written a simple stack implementation and would like some feedback as to what I could improve in my code and coding practices.
...
3
votes
1answer
24 views
OVH email manager script using docopt
This is what I coded to realize a command line program to make it easier to manage emails on ovh shared hostings. It's working ok but it seems ugly.
I'm a beginner with Python and ...
2
votes
2answers
64 views
Web-scraper for a larger program
I have a web scraper that I use in a part of a larger program. However, I feel like I semi-repeat my code a lot and take up a lot of room. Is there any way I can condense this code?
...
2
votes
1answer
27 views
CSV manipulation with Python
I've prepared a script to manipulate csv files in Windows that simply adds quotes as requested.
The script creates a backup of the original files and overwrite the wrong originals in its same folder.
...
2
votes
1answer
59 views
Simple sum calculator
I'm looking to optimize a simple sum calculator used in Project Euler+. The premise is simple: Find the sum of all the numbers divisible by 3 or 5 under X.
At first I did it like so:
...
3
votes
1answer
45 views
Long running Python “server status” collector
I wrote a small program that collects the server status, caches it for a certain amount of seconds, and then sends that to a mothership server. It's broken down into a few pieces, starting with ...
2
votes
0answers
75 views
Multipurpose command-line utility to manage a web application
I'm creating a command-line tool which is supposed to work on both Windows and Linux OS. It will be used to manage our application - start, stop, deploy etc.
We have it in bash scripts now (and it ...
4
votes
1answer
220 views
Optimizing critical loop for consuming a byte-buffer
I'm currently developing an Open Source project called sims3py using Python2.7. One overarching goal of the project is to ensure a Pure Python implementation of functions currently available only ...
1
vote
0answers
20 views
Download a file from given URL and retry on connection errors
I wrote script for Python 2.78 which is supposed to download and save a file from a given URL using the requests library.
In case that a connection to the server can be established and a valid ...
4
votes
1answer
56 views
Class-based user input validation
Having contributed to this Community Wiki on StackOverflow regarding validating user input, I thought I'd finally sit down and write something more robust to do these kinds of tasks. I wanted ...
3
votes
1answer
47 views
N-puzzle program solved using A* search
I coded the following program to solve the n-puzzle problem with n = 3. Are there any suggestions regarding readability and variable names?
...
3
votes
4answers
170 views
Count the ways to partition an array into two equal sets
I need to count the number of ways to partition an array into two contiguous arrays such that those arrays contain exactly same set of items.
Suppose ...
3
votes
2answers
117 views
Reverse Polish Notation calculator in Python
After reading the definition, I made a simple Reverse Polish Notation (RPN) calculator in Python.
Originally it had just 4 operators (using import operator and a ...
3
votes
1answer
64 views
2 way communication Python socket
I'm trying to create a 2 way communication socket in python. The socket will listen for connections from the client until it gets the data formatted in string like this: 'PHONENUMBER|STATUS'. I will ...
0
votes
0answers
18 views
Reload pickled objects into dict - assigned to variable name from file name
I'm doing a bunch of work with echonest audio objects (as returned by the echonest API) in the Python CLI and rather than having to recreate them each time, they can be saved.
This bit of code ...
3
votes
2answers
656 views
Tic-Tac-Toe solver
As a programming exercise, I've attempted a Tic-Tac-Toe solver which takes a finished board and determines a winner.
On top of checks for malformed input/ambiguous games (e.g. both players with ...
6
votes
1answer
142 views
4
votes
2answers
55 views
Reading and Writing in same script
I just finished working through Exercise 16 of Learn Python The Hard Way.
To further study, I wanted to create a script that will read and display a file's contents on screen, and then have the user ...
10
votes
2answers
133 views
Gimme some random passwords
pwgen is a nice password generator utility.
When you run it, it fills the terminal with a bunch of random passwords,
giving you many options to choose from and ...
1
vote
1answer
31 views
Expiring in-memory cache module
I needed a simple expiring in-memory cache module for a project I'm working on and I've come up with the following.
My requirements for the cache module are:
Be able to expire objects after certain ...
3
votes
0answers
76 views
Pure Python script that saves html page with all images
Here is pure Python script that saves html page without CSS but with all images on it and replaces all hrefs with path of image on hard drive.
I know that there are great libraries like ...
2
votes
1answer
76 views
XOR of a list of a numbers
In preparing a solution for the CodeChef "Will India Win" challenge, I am trying to find out the xor of list of numbers.
The first line of input contains the number of test cases, 1 ≤ T ≤ 106.
...
3
votes
2answers
52 views
Create SQLite backups
I have this script for creating SQLite backups, and I was wondering whether you'd have any suggestions on how to improve this. I was thinking that maybe it should create the backup ...
4
votes
1answer
80 views
Universal memoization decorator
I've just written a simple caching / memoization python decorator. It's purpose is to cache what the function returns for all the arguments combinations it's been ever invoked with.
So, if, say, we ...
4
votes
0answers
64 views
Visualize Parts of Song as Analyzed by Echonest
This is the a bit of code that works with Echonest API's pyechonest and remix libraries combined with matplotlib.pyplot to offer a simple visual representation of the start and end "parts" of a music ...
3
votes
1answer
71 views
Iterate over coordinates and correct constraint violations
I am creating an algorithm to take a series of labelled points placed randomly and move them until they fulfil a set of constraints.
The constraints have been pre-computed and are each a lower and ...
3
votes
1answer
53 views
Parse data into three logs
In the bit of code below:
How can I make add_day, add_ week and add_month work as a single ...
4
votes
4answers
615 views
Squaring an integer by repetitive addition
I've written two functions:
is_integer(), which tries to get a positive or a negative integer as input and returns the same value.
...
2
votes
1answer
38 views
Fetching and displaying the provisioning status of a phone number
I have the following function:
...
3
votes
2answers
55 views
Number of files with specific file size ranges
I am trying to write a script that will traverse through my directory and sub directory and list the number of files in a specific size.
For example, 0kb-1kb: 3, 1kb-4kb:4, 4-16KB: 4, 16kb-64-kb:11. ...
3
votes
5answers
163 views
Getting a 4.0 GPA
This is my code, for calculating a GPA for 7 subjects. It works, but is there a better way? Any hints on making it more flexible?
...
7
votes
5answers
652 views
Interactive dice simulator
After finishing my course on CodeAcademy, I wanted to write a program. Please provide opinions.
...
1
vote
1answer
82 views
Transposing rows and columns for file contents [closed]
This program transposes rows and columns for file contents:
...
2
votes
1answer
54 views
Ping function in Python
Below is a piece of code which takes a list of IPs, pings the hosts and returns (prints) the list for "Alive" and "Dead". Any feedback on what can be done better is welcomed, mainly, speed and ...
8
votes
3answers
195 views
1
vote
1answer
52 views
Python Koans multiplayer Greed Game (dice)
I finished the Python Koans because I wanted to practise Python and I completed the extra assignment which is the Greed Game (see the rules here).
Here is the code, I think there are no flaws but you ...
4
votes
2answers
141 views
Reflecting emotion classification based on the Lövheim cube
Background
I created a simple class to reflect emotion classification based on the Lövheim cube. The code is not scientific at all, and I just did it for fun, but I want all code I write to be as ...
1
vote
3answers
67 views
Python greed roll
I am doing the Python Koans to practise Python a bit more and I got to the greed dice project. It is a very simple dice game that scores a set of up to five rolls.
These are the rules:
...
6
votes
3answers
470 views
Optimizing an Anagram Solver
I've built an anagram solver in Python 2.7. It goes through a text file with over 100,000 words and checks if any permutations of the input matches the line. It works great, except it is very slow. ...
3
votes
1answer
65 views
Filtering with multiple inclusion and exclusion patterns
I have a requirement to be able to filter a list of strings by both inclusion and exclusion patterns (using fnmatch-style wildcards), of which there can be many.
...
2
votes
3answers
50 views
Function to combine list elements
I was working on a little project that at the end of the script would write to a CSV file. I had to create a function that would combine multiple list elements of the same size into a single one. I ...
4
votes
6answers
379 views
Hangman game in Python
While I'm not new to Python, this is my first 'bigger' Python program I created, also my first game in Python.
...
0
votes
4answers
99 views
Merge two dict in separate list by id
I have following data structure
>>> a = [{'id': 1, 'name': 'a'}, {'id': 2, 'name': 'b'}]
>>> b = [{'id': 1, 'age': 12}, {'id': 2, 'age': 21}]
I ...
1
vote
2answers
88 views
Class for multithreaded insert into database
Here I have class that supposed to take dictionaries of product objects and their articles (kind of unique identifier) from queue and insert or update them in database table.
Received dictionary ...
4
votes
5answers
122 views
Finding the occurrences of all words in movie scripts
I was wondering if someone could tell me things I could improve in this code. This is one of my first Python projects. This program gets the script of a movie (in this case Interstellar) and then ...
7
votes
3answers
78 views
Checking for intersection points
The aim of the program is to find those points which comes under the intersection of at least 2 circles.(space is a 1000x1000 matrix)
...
3
votes
2answers
77 views
Process zip files
I have zip bundle, for example, abcd.zip, contains more zips like 1.zip, 2.zip etc. Inside of each child zip there is a .jpg file like 1.jpg, 2.jpg etc. There are so many other files but I need only ...
10
votes
3answers
709 views
Counting Vowels
I'm learning to program and I've chosen Python as my first language. I've written a function to count vowels in a string and print the number of occurrences of each of them. Please review my code and ...