Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

0
votes
1answer
9 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 ...
0
votes
1answer
15 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 ...
0
votes
0answers
8 views

Read a Tab Separated File and Assign Each Column to a Separate Variable [on hold]

The following python code reads a tab separated file which contains multiple columns. I have store each column in a separate variable then tried to store the column into a dictionary and print out the ...
5
votes
2answers
301 views

Leap year calculator

I'm creating a program to determine whether or not a given year is a leap year. I just wanted to get anyone's feedback on it. I am aware of the calendar module in Python. I just wanted to try it from ...
-1
votes
0answers
21 views

Factory for making buttons and other HTML tags

There is a lot of explanation on Factory Design Pattern in Code Review. However, I cannot find an example in python, so here is sample code which I want to use in my project (class names are changed). ...
2
votes
1answer
23 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: ...
0
votes
0answers
8 views
1
vote
0answers
12 views

Django Model field naming convention for lookup tables

I'm currently in the process of refactoring a Django app to use Django REST Framework. Within the existing code there are 15 models for lookup tables. The structure of each model is as follows (using ...
3
votes
1answer
20 views

Speed up script that calculates distribution of every character from user input

I have a data set with close to 6 million rows of user input. Specifically, users were supposed to type in their email addresses, but because there was not pattern validation put in place we have a ...
-1
votes
0answers
21 views

Linked List in Python [on hold]

I currently have a functioning piece of coding that correctly works using a linked list in Python. I am currently trying to error proof the code so that if the user selects number 3 on the menu the ...
-1
votes
0answers
11 views

Implementing modified binary search in python. [on hold]

The problem is to find the index of the element which is less than or equal to N. To tackle the problem, I wrote the following code but it seems to be not working. ...
2
votes
0answers
26 views

Python proxy class

I've coded my own proxy class in python. The aim is to have a different type() but otherwise behave as identical to the underlying object as possible. I'm wondering ...
-1
votes
0answers
33 views

Python, vowel detection [on hold]

I have written the code that will be checking number of vowels in each string and then removing the text that has the correct number of vowels. Here is the code: ...
0
votes
1answer
29 views

Changing the id field to an _id field for the lowest tweet id

I am collecting tweets using a Python script and I want to store them in a MongoDB database. I want to find out the lowest tweet id and for each tweet, I want to change the ...
2
votes
1answer
27 views

Caesar cipher mod 127 with cyclical keys

This is my code for encryption and decryption when the key = 'a'. I'm just a little confused on how to make it work when the key contains multiple characters, key = 'abc' for example. If anyone could ...
1
vote
0answers
31 views

Memory game with Turtle

A while back I had to do a project for school in Python, creating a game or something interesting. I decided to make a memory game. The code isn't really nice and neither are the variable names. It's ...
1
vote
3answers
46 views

Searching text for a string

This is my current code: ...
3
votes
0answers
29 views

Time limit exceeded for SPOJ problem Prime generator

Input The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, ...
-1
votes
0answers
21 views

Creating a fixed calculator in Python 3 [on hold]

I am new to Python and I am trying to create a calculator to do a complex calculation. I need it to take input from a user and do deductions and multiplication based on that input. The scenario ...
0
votes
0answers
18 views

Inheritance after instantiation? [on hold]

Problem When writing context-aware class wrappers, I found that regular inheritance wasn't usable. Leaving me with the task of writing very light wrappers over the "parent" class wrapper: ...
1
vote
2answers
42 views

Keeping attribute names simple when using getters and setters

Is the use of _pn in __init__ pythonic? It seems that most examples change the actual attribute to ...
0
votes
0answers
7 views

TextFile into a dictionary [on hold]

I need help with reading my TextFile into a dictionary. My textfile is the following: loan 2 debt 3 rate 2 help 1 cousin 1 lawyer 1 Now I need to convert this into a dictionary. I have experimented, ...
2
votes
0answers
12 views

Parsing URLs in Pandas DataFrame

I'm working on a project, and the client needs their Google AdWords destination URL query parsed, and the values spell checked to eliminate any typos (use instead of us, etc). So what I'm doing is ...
2
votes
1answer
49 views

Word Jumble in Python

This game that I semi coded is a little bulky and kind of boring. I want to know if there is anything simple I can do to shrink it and add a little spice to the code. ...
3
votes
3answers
29 views

Flask route to pull data from database for getJSON to process

I am developing a reporting application in Flask where I pull data in a route function from a postgresql database and jsonify the data. On the client side I have ...
3
votes
2answers
45 views

Calculating Exponential Moving Average in Python

I'm in the process of creating a forex trading algorithm and wanted to try my shot at calculating EMA (Exponential Moving Averages). My results appear to be correct (compared to the calculations I did ...
2
votes
1answer
35 views

Making Tic-Tac-Toe winning check more efficient

My code works perfectly fine and I would just like to clean it up a little. From the research I've done, I cannot find anyone that used a multidimensional list to a game of TTT. I'm just looking for a ...
-2
votes
0answers
13 views

Text-Based game isn't accepting user input to flow through the next options [closed]

I'm doing a text based game for an assignment, and I can't seem to get this bit of code to work properly. For some reason when it gets to the if userInputList[0]=="yes": It's not going onto the next ...
-1
votes
0answers
27 views

Python: Program to create list of all english wikipedia articles [closed]

This program will scrape wikipedia to create a list of all english wikipedia articles. How can I improve this program as it currently performs very bad performance-wise. On my internet connection it ...
9
votes
1answer
1k views

Amateur RPG Fun

I am looking for this code to look neater, and if possible, less bulky. I am new to def and to dictionaries, so I think throwing a few of those in here could ...
2
votes
1answer
39 views

Extracting a subgraph

Given a huge graph, I want to traverse it, in the fastest way possible, and extract a subgraph with the following properties: the starting node is specified the maximum number of elements and max ...
4
votes
1answer
46 views

Streaming hacker news posts

EDIT: Thanks for the answer. I took suggestions from here and readings elsewhere and have completely refactored it, link. Hacker News recently released an official API. Unfortunately, it cannot be ...
0
votes
1answer
25 views

Improving excution time for list and sampling in Python

Here is my code for generating edge list based on Price model algorithm. I think there have two points to reduce execution time: use proper data type use faster random sampling Originally, I used ...
7
votes
4answers
322 views

Kaprekar's constant

I'm new to Python and as a first exercise, I've written a function (module?) to calculate Kaprekar's constant using Python 3. I'd like some feedback on whether this is Pythonic enough, and if I can ...
1
vote
1answer
33 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 ...
1
vote
2answers
73 views

Stop connecting to a server after n unsuccessful attempts

I am trying to connect to a server. If the connection goes through, then print an apt message. If the connection does not go through, try for a total of n times. And quit after the nth attempt ...
-3
votes
0answers
33 views

adding elements to list in python [closed]

Sorry if this is a silly question.In python result = [] if i.isalpha(): result += [i] or ...
2
votes
1answer
53 views

Motor degree movement function

I want to control a motor which rotates a device over a gear. Input values for the device are from 0 to 360 degrees. The motor should always rotate the device the shorter way around. For example, if ...
3
votes
2answers
59 views

List all classes in a package directory

I have a package directory pkg with several classes that I would like to build into a convenient dict property. The structure ...
1
vote
3answers
72 views

Basic text editor in Python with Tkinter

I have finished writing my nice and little text editor in Python with Tkinter. I tried to achieve the best user experience that I could. I want this code to be 2/3 compatible, I tested it in both ...
3
votes
3answers
764 views

Calculate highest prime factor very slow

Sometimes when I write a Python 3.x script with too many nested loops and some big values it just takes too long to give the answer. How can I optimize my code so that it runs faster, or where should ...
5
votes
0answers
53 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
108 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
1answer
41 views

Drawing a dashed line with pygame

...
5
votes
1answer
102 views

Codility MaxCounters Peformance in Python capping out at 77% performance

My problem is quite similar to the question found here, except I am attempting to answer the question in Python. Given an array of N counters, all initialized to 0, and an array ...
2
votes
0answers
48 views

Binary Index tree optimization

I have written code for binary index tree. My problem is there are many functions based on the binary index tree the function stores the sum of element within a given range of binary index tree and my ...
2
votes
1answer
67 views

Conway's Game of Life without objects

I was wondering if anyone could provide some feedback on my solution to Conway's game of life. I tried to solve it without using objects. It returns a dictionary of living points on a grid and points ...
1
vote
0answers
21 views

Is monkeypatching __builtin__ in tests like this an absurdly complicated practice?

My hunch: Probably. I'm testing a little magic behaviour of my script that automatically reads from ~/.ghtoken to do automagic authentication on GitHub API ...
3
votes
1answer
31 views

Rename files to titlecased

I wrote this Python script to rename specified files to "titlecase", for example: hello.txt to Hello.txt ...
2
votes
2answers
76 views

Extended Euclidean algorithm and modular multiplicative inverse element

After my first exercise here is another. Again, this is exactly that: Exercise, which means that the output doesn't necessarily need to be beautifully formatted, etc. I probably have some variable ...