Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.

learn more… | top users | synonyms

-2
votes
0answers
17 views

Convert to Threading and Queues? [on hold]

I'm looking to convert this working code to threading and queues instead of thread and global variables, but am not understanding how to do it. ...
2
votes
0answers
35 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
55 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. ...
2
votes
2answers
20 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
64 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
52 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
61 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
50 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
591 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
32 views
3
votes
2answers
47 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
148 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? ...
5
votes
5answers
602 views

Interactive dice simulator

After finishing my course on CodeAcademy, I wanted to write a program. Please provide opinions. ...
1
vote
1answer
51 views

Transposing rows and columns for file contents [closed]

This program transposes rows and columns for file contents: ...
2
votes
1answer
39 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
110 views

Bulls and Cows in Python

I have recently written this little Bulls and Cows game in Python: ...
1
vote
1answer
41 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
116 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
59 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
324 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
47 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
49 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
369 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
70 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
81 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
106 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
63 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
68 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
548 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 ...
2
votes
1answer
32 views

Write to a new, modified Excel file from an original one

I noticed that I've a HUGE bottleneck in this following function of mine. I can't see how to make it faster. These are the profiling test results(keep in mind that I'm using a PyQt GUI so times can ...
0
votes
1answer
75 views

Find a string in a Excel cell in the fastest way

I have to implement a "filter" in a Excel file which deletes/shows particular strings found in specified columns. I save the rows numbers that have to be deleted in a list. I have my filters in ...
6
votes
2answers
255 views

Low-level methods with temperature conversion program

This is my first program to convert temperatures. I have a very basic knowledge of Python and I tried using only what I already knew to make the program. What are some improvements I can make, or how ...
4
votes
1answer
69 views

Representation of the formula P(n) = (n!)(6^n)

I'm trying to represent the following mathematical expression in Python: $$P(n) = (n!)(6^n)$$ The program should compute the answer to expression when n = 156. I ...
2
votes
1answer
24 views

Split CSV by Repeated cells python

Any time that a row ID (oddly placed in column 8, i.e. row[7]) is repeated after the first instance, I want to write those rows into a second file. The code I'm using is extremely slow -- it's a ...
2
votes
3answers
40 views

Simple shared resource in Python

I want a 4-bit resource to share status between processes and to retain status after shutdown and reboot. If the system were a microprocessor, I'd use a 4-bit register in non-volatile memory. ...
4
votes
2answers
112 views

Twin Prime Algorithm Optimization

I have wrote the following algorithm to print out the Nth twin prime numbers: ...
1
vote
1answer
34 views

A `get_context_data` method for selecting and updating images displayed to a user over a multi page form

Below are the get_context_data method and the done method of a SesionWizardView. A SessionWizardView is designed to split a form over multiple pages. The ...
3
votes
1answer
27 views

URL selection function that is designed to randomly assign users to different surveys until full

I'm trying to condense some of my code to make it more maintainable and to learn a few new tricks. Below is a Python 2.7 / Django 1.6 function which is designed to assign users to one of three ...
2
votes
1answer
40 views

Parse a csv file and create a dictionary of partial results

I have a bunch of .csv files which I have to read and look for data. The .csv file is of the format: ...
1
vote
1answer
42 views

Random Distribution to fit an Average Python

This is from my own question on Stack Overflow. I want to get average numbers from a range such that they fit an intended average. I expect something bell-curve-like, but asymmetrical unless the ...
5
votes
0answers
87 views

Virtual machine management with decorated selfies

I have a class which provides various methods for retrieving information from a VMware vSphere environment. Over the time my class got extended and became large, so I thought I should spend some ...
4
votes
2answers
152 views

Testing whether a given string has unique characters

Here is my code which tests whether a given string has unique characters. The function is_unique which does a linear search for each character in the string is ...
1
vote
2answers
127 views

Sieve of Erathosthenes speedup

While reading HackerNews, I learned about a data set of the first 50 million primes. This would be a lot, but his website has disclaimer: n this directory I have the first fifty million primes in ...
3
votes
2answers
577 views

Count occurrence of words in a .txt file

I'm taking an intro to programming class and although I've learned some things I didn't know before (I've been using Python for about 1.5 years) I feel like I've not progressed much in writing ...
1
vote
1answer
43 views

Function to return percentages in Python

I created a function for giving me percentages from two integers. I want two decimal places in the result. ...
23
votes
4answers
3k views

Someone thinks poorly of my server log parser

I have just been informed that the following code written by me is extremely poor. I have absolutely no idea why. It is memory efficient, and looks clean to me. But still the feedback is very poor. I ...
1
vote
1answer
11 views

Subclassing Profile.Profile to use it as a context manager

I was profiling my code and annoyed by the continuous calls of Profile.run(my_function()) Profile.run(my_next_function()) so I decided to make a context manager ...
1
vote
0answers
81 views

Optimize QuadTree to find K Nearest Neighbors

I'm looking a way to make my k nearest neighbors search more efficient. The context of the question is that I'm given a list of topics that have a unique ID (integer) and a (x,y) coordinate (floats) ...
4
votes
2answers
83 views

Custom sorting a list of objects efficiently

I'm trying to make sorting of objects in my program as fast as possible. I know that sorting with a cmp function is deprecated in python 3.x and that using keys is faster, but I'm not sure how to get ...
7
votes
5answers
427 views

Python odd number diamond

I worked up a quick diamond program that takes only odd numbers while returning an error with even numbers or 0. The code looks rather ugly to me, especially with the recurring ...