Tagged Questions
12
votes
4answers
784 views
Improvement on these horrible nested for loops?
This does the job, but is not especially elegant.
What is the preferred Pythonic idiom to my childish nests?
def bytexor(a, b):
res = ""
for x, y in zip(a, b):
if (x == "1" and y == ...
5
votes
2answers
160 views
How to improve this Python code (complicated looping)
Basically, I have a list, newtry of blocks and I want to find a value of catchtype that makes them all return true for block.isCatchExtendable(newhandler, catchtype) or report an error if this can't ...
4
votes
2answers
152 views
Reading a controll character in a loop in Python
I have a code snippet bellow and because of habit from other programming languages I wanted to use rather do-while loop. But Python offers only the construct which I show as a second code snippet ...
4
votes
3answers
180 views
How to increase the performance of loop in Python?
I need to run over a log file with plenty of entries (25+GB) in Python to extract some log times.
The snippet below works.
On my test file, I'm ending up with roughly 9:30min (Python) and 4:30min ...
4
votes
1answer
137 views
Optimizing Python / Numpy Code
So I'm implementing a version of the mean shift image processing algorithm for color segmentation in python/numpy.
I've written a pure numpy version of the actual mean shifting per pixel (which I ...
3
votes
4answers
197 views
Optimize beginner Python loop
I'm a rank beginner in Python, and I am working my way through various relevant OpenCourseware modules. In response to the prompt
Write a procedure that takes a list of numbers, nums, and a ...
3
votes
2answers
428 views
Overly 'Loopy' python code, would like to improve (with numpy/scipy if possible)
I have the following code
import itertools
#defines the array of numbers and the two columns
number = [53, 64, 68, 71, 77, 82, 85]
col_one = []
col_two = []
#creates an array that holds the first ...
3
votes
2answers
305 views
I want to create a photo changer loop in python. Can someone check my code?
I just started python a few days ago, and I haven't programmed much before. I know my code is terrible; however, I would like someone to look it over. What I'm trying to do is create a photo "loop" ...
3
votes
2answers
173 views
Removing the massive amount of for-loops in this code
Are there ways to avoid this triply nested for-loop?
def add_random_fields():
from numpy.random import rand
server = couchdb.Server()
databases = [database for database in server if not ...
2
votes
4answers
122 views
Retrieving lists of consecutive capitalised words from a list
Ok, so given the string:
s = "Born in Honolulu Hawaii Obama is a graduate of Columbia University and Harvard Law School"
I want to retrieve:
[ ["Born"], ["Honolulu", "Hawaii", "Obama"], ...
2
votes
2answers
131 views
Speed up two for-loops?
The code below is slow. Any thoughts on speeding up?
dict1 = {}
dict2 = {}
list_needed = []
for val in dict1.itervalues():
for k,v in d1ct2.iteritems():
if val == k:
...
2
votes
1answer
57 views
Generic pass_many(vals, pass_one) to unroll and call pass_one(val)?
I'm trying to create a generic function that takes a data-structure as input and then sends each non-empty item—e.g.: str, int—individually:
def print_this(v, delim1="", delim2=""):
print v, ...
1
vote
1answer
56 views
Django how to make this view faster?
I have view and it works correct, but very slow
class Reading(models.Model):
meter = models.ForeignKey(Meter, verbose_name=_('meter'))
reading = models.FloatField(verbose_name=_('reading'))
...
0
votes
1answer
60 views
Improvment of and looping in a regular expression pattern
My implemented regex pattern contains two repeating symbols: \d{2}\. and <p>(.*)</p>. I want to get rid of this repetition and asked myself if there is a way to loop in Python's regular ...