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

1
vote
0answers
170 views

Relatively simple function that mainly performs arithmetic is called many times - naive optimization using Cython by defining types causes slowdowns

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 ...
1
vote
2answers
23 views

Code for showing installed python packages/modules

Any comments about style (especially any "non-pythonic" code), performance, readability, etc would be much appreciated! I've tested this on CentOS and OSX 10.9. Works for Python 2.7 and 3. ...
0
votes
1answer
16 views

Round division to two decimal places [on hold]

I'm working on a revision of my electrical calculator. I used string formatting to round the answers it gives to two decimal places. On the operations that require multiplication (voltage, wattage), ...
5
votes
2answers
47 views

Pythonic quicksort algorithm

Is my implementation of quicksort efficient, in-place, pythonic ? ...
5
votes
1answer
157 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
71 views

Read from csv file, transform to dictionnary

First of all, here's the code I'm working on: ...
4
votes
2answers
79 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 ...
-2
votes
0answers
20 views

Short way to search text

Making an email program, I know that there has to be a better way to do this. ...
8
votes
3answers
285 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
49 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
39 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 ...
3
votes
2answers
200 views

Join argv list with spaces

I'm a Python noob. This is the code I'm using: ...
2
votes
1answer
20 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
74 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 ...
3
votes
1answer
74 views

K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
2
votes
2answers
39 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
5answers
394 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 ...
5
votes
1answer
67 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 ...
7
votes
1answer
122 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
123 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
80 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, ...
4
votes
2answers
84 views

Readable way to print a list of things 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 indices. There are a couple of simple ways to do this in Python, ...
5
votes
1answer
48 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 ...
1
vote
0answers
18 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 ...
3
votes
1answer
65 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 ...
3
votes
3answers
211 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 ...
3
votes
1answer
42 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
93 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. ...
1
vote
0answers
76 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
104 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
112 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
116 views

Basic Brainfuck interpreter (part 2)

I have this obsession with esoteric programming languages. So I decided to spiff up my previous Brainfuck interpreter. ...
1
vote
0answers
41 views

Microcast algorithm

Following is the main file in the project (executing tasks). It uses the mpi4py module, and multiple processes execute the same code. Please review the code and ...
2
votes
1answer
37 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
133 views

Wedding Photography Cost Calculator

This is my first code. I would really appreciate a critique for it, if anyone can spare the time. ...
5
votes
1answer
386 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
2answers
86 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 ...
1
vote
1answer
43 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
114 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. ...
7
votes
1answer
236 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 ...
15
votes
1answer
165 views

Python - Minesweeper

I'm new to Python (and generally to programming), and I have recently written this Minesweeper game: ...
4
votes
2answers
40 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
91 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. ...
5
votes
1answer
39 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
87 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 ...
4
votes
1answer
151 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
96 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
39 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
50 views

Convert 2D list to dict of list of index

I have a 2D list like this: ...