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
1answer
2k views

jQuery slider in a Python/Django SessionWizardView

I have created a Data Verification page in a Django SessionWizardView where a user has to confirm an earlier submitted rating of an image using a jQuery UI Slider (-...
3
votes
1answer
329 views

Python code to write simple VPK archive files

I'm new to Python, but have a lot of experience with C and C++. I would appreciate some feedback on my implementation of a packer for this archive format. Specifically, any feedback on how idiomatic ...
6
votes
3answers
35k views

Padding a hexadecimal string with zeros

I'm given a hexadecimal number in string form with a leading "0x" that may contain 1-8 digits, but I need to pad the number with zeros so that it always has 8 ...
4
votes
1answer
465 views

Sum of numbers which are not sum of two abundant numbers

The following program is a solution to Project Euler Problem 23. That problem defines an abundant number to be one whose sum of proper divisors is greater than it, tells us that all integers at least ...
4
votes
2answers
138 views

Summing all parameters, except the last, which should be subtracted instead

Working on some python koans and got one which states: ...
4
votes
2answers
2k views

Finding 10-unique-digit number with i-first-digits divisible by i

I was posed this question by a friend: I am a natural number written with 10 different digits such that for all \$i ∈ {1, . . ., 10}\$ the number formed by my \$i\$ first digits (from left to right)...
3
votes
1answer
2k views

Backup files script

I'm creating own script for backup user's directories. CentOS 6.5; Python 2.6. Directories looks like: ...
2
votes
1answer
543 views

Speed up a function using NumPy

I have a function written in Python 2.7 that I call several times in a program. This function is rather slow, and I'd like to rewrite it in NumPy. However, I don't know how to do it. I basically have ...
10
votes
4answers
26k views

Simplify a fraction

I have been learning Python for a while (my first programming language) in my spare time. Since it's been 20 years since math class, and I didn't get very far with that, I just brushed up on pre-...
2
votes
1answer
87 views

Print dict with varying-length lists

Is there a shorter way of taking a dict with varying length lists and printing it to screen? Shortcomings of this method also include that values which aren't lists are printed as letters separated by ...
5
votes
1answer
1k views

Pygame menu to launch games - follow up

Follow up of Pygame menu to launch games I rewrote most of the code per the one answer. I'm looking for further advice to improve to the code. I'm afraid some of the abstraction may be too Java-like. ...
5
votes
1answer
4k views

Regular expressions - match only specified string length

I'm learning regex. Here I'm checking a string of type aA1 but want also to check it is only 3 characters long. Is there a better way of doing it please? ...
0
votes
1answer
39 views

Observing PEP maximum line size, particularly when formatting localized timestamps [closed]

I have this function that I use to publish a message but I need to do this long conversion for time and date. Maybe there's a better way to convert it to make smaller. Otherwise I'm stuck with this ...
4
votes
1answer
58 views

Filtering runtime processes to see if is a runaway process

I'm trying to improve readability and performance, either by reordering the logic of my code or just syntactically being smarter. Basically, I gather the running processes from Db and then I parse ...
1
vote
1answer
2k views

Matching PEP8 style with long one line for loop [closed]

I'm working with Python 2.7.5 and I'm trying to make it match the PEP8 coding style. I have a few one line for loops but the issue is that they are each above 80 ...
1
vote
2answers
1k views

Basic search engine

I want to improve efficiency of this search engine. It works in about 10 seconds for a search depth of 1, but 4 minutes at 2 etc. I tried to give straightforward comments and variable names, any ...
2
votes
1answer
80 views

Conditional statements with doctor and patient information

I'm focusing on trying to write clean, modular Python 2.7.5 code. ...
3
votes
2answers
99 views

Optimising and condensing Django View Class

This follows on from a previous question I asked which was of huge help to me. I am still only learning Python and Django and I would love to learn how to code better. The below is a ...
10
votes
3answers
924 views

Displaying information about people from a JSON file

I'm working with Python 2.7.5 and I have written the following code: ...
9
votes
4answers
1k views

Scissors, Paper, Rock in Python

The game works, but I was wondering if anyone could help me with better structure for the code, simplification, or just any other improvements. ...
6
votes
1answer
828 views

Dict of names and birth dates which prints with age at birthday of current year

As a beginner (Learn Python the Hard Way), I've set myself this exercise with classes and it works but looks very inelegant to me. I'm trying to write classes which could be re-used in other code. I'...
3
votes
2answers
368 views

Calculating the push or pull force of a molecule at a vertex

The basic idea of the code is to calculate the push or pull force at a vertex, given the number of "push causing molecules" and "pull causing molecules" at a polygon vertex. The code thus mainly ...
7
votes
2answers
837 views

Pythonic quicksort algorithm

Is my implementation of quicksort efficient, in-place, pythonic ? ...
6
votes
1answer
776 views

Implementing graph search

I am very new in Python, I would like to know if the style presented below attends a good implementation in Python. ...
3
votes
1answer
655 views

Read from csv file, transform to dictionnary

First of all, here's the code I'm working on: ...
4
votes
2answers
11k views

Tic-Tac-Toe game using the minimax algorithm

I have written a Tic-Tac-Toe game in Python that contains, among others, a player that uses the minimax algorithm. I am not exactly a beginner at Python, but I'm not very experienced with it - so I ...
8
votes
3answers
6k views

Electricity Calculator

This is a calculator for Ohm's Law and Power Law. It works but I'd like some suggestions on making the code look a little cleaner, or run more efficiently. ...
2
votes
1answer
197 views

Shift\Transform characters in a grid

I wrote this program for a code test on some website. This program do some predefined transformations (transformation can be horizontally, vertically or by shifting to given number of keys) for every ...
3
votes
1answer
4k views

String to (Multidimensional) List Conversion

Some background: I'm writing a number of classes that ensure user input is properly validated, and is rejected if it does not conform to expected types (there's also some extra options such as ...
5
votes
2answers
3k views

Join argv list with spaces

I'm a Python noob. This is the code I'm using: ...
2
votes
1answer
179 views

Reduce and condense a non standard SessionWizardView

As I'm slowly getting the hang of Python and Django I'm becoming increasingly worried about the volume/quality of code I have. This is my first time building a Python/Django Application and I'm ...
3
votes
2answers
164 views

Answer to an implementation of Project Euler #8

I saw that there was a previous question asking to review an answer to the Project Euler question #8. My answer didn't look anything like the answer in that question and as a beginner, I was wondering ...
9
votes
1answer
13k views

K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
4
votes
2answers
78 views

Basic value comparisons

I made a value comparison "programming language" similar to a previous one I made, except this one is based solely on value comparisons. ...
7
votes
4answers
652 views

Python code for detecting a single item moved in a list

I need to write a function that takes an original list of unique values and a resulting list: [0,1,2,3] [0,3,1,2] and detect that only a single element was moved ...
6
votes
1answer
282 views

Increase the speed of this Caesar Cipher

Here's my attempt at a Caesar Cipher encoder/decoder. If given a key, it will encrypt the given string. However, if you do not specify a key, it checks each of the 26 possible keys and returns the ...
12
votes
1answer
6k views

Optimizing “Poker hands” challenge solution

I'm trying to solve the project Euler problem 54. In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: High Card: Highest ...
6
votes
1answer
898 views

Light Python pubsub lib, but is it too light?

In attempting to decouple the object from the messaging I came up with the following short code for adding publish-subscribe functionality to a Python script. ...
4
votes
3answers
1k views

Validate parameters within a range

Function to use several blocks of if:elif:else: that all take slightly different conditional statements. I'm trying to format integers into a 2 digit string, ...
6
votes
2answers
324 views

Print a space separated list in Python

I am trying to solve the common "print a character after every item in a list, except the last one" problem. I do not want to use list indexes. There are a couple of simple ways to do this in Python, ...
5
votes
2answers
497 views

Map reduce tester ported from bash to Python

My MapReduce tester is clearly ported from Shell, short of args=None for line in args or read_input(), what's a better way of ...
2
votes
0answers
169 views

Function that transforms input file based on a numpy poly1d function

I have written a function that gets a function as input (acquired from numpy.poly1d). The function has access to the GUI variables ...
5
votes
1answer
155 views

Random “programming language”

I decided to write my own programming language, of sorts. Essentially, you write code into a text file and the program will run the code inside the text file. The file is provided through a script ...
5
votes
3answers
879 views

Basic math interpreter

Essentially what I've done here is written an Interpreter that takes in Python math, such as this, 23 ** 374748, and prints out the result. This program relies on ...
4
votes
1answer
1k views

Content filtering of webpage

This is code for filtering the data of webpage, for the web crawler I made for my project. I know python scripts can lag than other languages, but this takes a lot of time when processing even a ...
2
votes
2answers
4k views

Upload and resize image

I have implemented following code to upload and resize image in Django. Please suggest ways to make it more pythonic. ...
2
votes
0answers
2k views

Encrypt texts, with saved password using pycrypto

I have the code bellow, which is supposed to be used inside a larger program. Please see notes about the requirements below the code. ...
2
votes
3answers
3k views

Basic terrain generator

I've decided to try and start programming using Object-Oriented-Programming, so I built a small terrain generator that could be done using something as simple as this: ...
4
votes
2answers
3k 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 ...
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. ...