Tagged Questions
-1
votes
0answers
10 views
Iteratively copy wildcard named folder and files [on hold]
I'm new to Python. I'm running version 3.3. I'd like to iteratively copy all wildcard named folders and files from the C drive to a network share. Wildcard named folders are called "Test_1", ...
0
votes
2answers
152 views
1
vote
2answers
286 views
The efficiency of looping over nested dictionaries in Python
How to make the following code more efficient?
...
1
vote
0answers
16 views
Editing Surfaces Removing Color
So I have recently tried to load an image and save it, but remove all of a certain color. I'm running the program and it is running really slow, is there a more efficient way to edit an image? My code ...
-2
votes
1answer
44 views
Optimizimg ugly if else loop in python [closed]
So, I`m getting some values from large nested dictionary.
s_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] and f_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] ...
0
votes
1answer
34 views
For and if loops in Python math game [closed]
I'm trying to get my program to iterate through a loop after a person gets the correct answers to the first question. I feel like there is a better way to do things syntactically.
...
2
votes
2answers
190 views
Making a nested loop structure more pythonic
I'm looking for a review on my code. I am also looking for ways to transform this function into something more Pythonic. I'm fairly new to Python, so any advice would be appreciated.
...
4
votes
1answer
61 views
Loop cleanly through different classes
If I have a number of different classes which manage certain tests. At the moment I have to launch each test individually which results in a lot of if statements.
...
7
votes
1answer
71 views
Compute stats on two class vectors
Below is a full working code example of code which is used to compute stats on two class vectors (partitions).
There are two functions:
pairwise_indication and
...
7
votes
2answers
710 views
Repetitive For Loops in 2048 Game
I have the following function defined in a program that implements the 2048 game. I tried condensing the repeating part of the code into one loop containing +1 offset variables for the indices, which ...
2
votes
2answers
74 views
Optimizing Python code for Project Euler #5 (LCM of all numbers from 1 to 20)
This is my solution for the 5th problem of Project Euler, which asks for the least common multiples of the numbers from 1 to 20 (inclusive). Is there any way to improve the while loop conditional ...
8
votes
3answers
91 views
List iteration, creation, or comprehension
I suspect that this can be done in a much neater way using list comprehension in python:
...
4
votes
3answers
733 views
Do-While loop in Python, with limit on the amount of 'do's
I'm in a location with poor Internet access. In order to ensure that a call to an external service succeeds, I am wrapping the call in a pseudo-do-while in Python. ...
4
votes
2answers
81 views
Removing redundant lines from script
Context: I've been learning Python for a few months and I'm able to write codes which do work, but they normally look very ugly and contain a lot of unnecessary code. But I normally struggle to find ...
2
votes
1answer
115 views
Drawing a table in Python3
I have created a module to draw text tables. The relevant parts are below and here's the full code for txtable).
...
1
vote
2answers
84 views
How to refract a while loop with a necessary initial setting?
I put the readable version into the gist file -> link
Please ignore the print and comment in the following code.
I often have ...
0
votes
2answers
142 views
Which loop code is better practice?
def minval(xs):
minum = xs[0]
for i in range(len(xs)):
if xs[i] < minum: #difference in code: xs[i]
minum = xs[i]
return minum
...
1
vote
1answer
109 views
Pythonic loop logic for Tic-Tac-Toe game board
I have a while loop below, but I'm not quite sure if it's the most 'pythonic' thing. I've omitted most of the code, and have the skeletal structure below (but have ...
0
votes
1answer
126 views
Filtering a long list of files through a set of ignore patterns using iterators
I have a backup job that walks across a huge directory with potentially millions of files. Python's os.walk() works just fine.
Now, I have implemented a feature to ignore files based in a black list ...
0
votes
1answer
1k views
0
votes
1answer
70 views
Looping over a list [closed]
I'm new to Python, and I have a small section of code which works fine when outside of a function:
...
2
votes
1answer
148 views
Optimising If statement and for loops
I have two solutions (in jython) to take two pictures and copy and paste alternate sections of one picture to the other, like so:
...
1
vote
2answers
137 views
Is there a better, more efficient way to write this loop?
While working with someone else's code I've isolated a time-killer in the (very large) script. Basically this program runs through a list of thousands and thousands of objects to find matches to an ...
2
votes
2answers
131 views
I'm practicing turning for loops into recursive functions. what do you think?
I am trying to turn this function:
collection = ['hey', 5, 'd']
for x in collection:
print(x)
Into this one:
...
1
vote
2answers
220 views
Making a 2D dict readable
I am building a 2d dictionary with an altered list at the end Afterwords I want to find the min of each list. Is there a better way to do it? Better being faster or at least less of an eyesore.
...
2
votes
1answer
512 views
Leaving an APScheduler in a while True loop
I want to run a background job on my web server to do some database maintenance. I am looking at using APScheduler to do this.
I am planning on running the below ...
0
votes
1answer
76 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 ...
4
votes
3answers
915 views
Running over a log file to extract log times
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 ...
1
vote
1answer
88 views
3
votes
2answers
182 views
Removing the massive amount of for-loops in this code
Are there ways to avoid this triply nested for-loop?
...
2
votes
4answers
158 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:
...
13
votes
4answers
1k 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?
...
4
votes
1answer
240 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 ...
5
votes
2answers
198 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 ...
3
votes
4answers
254 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 ...
1
vote
2answers
193 views
2
votes
1answer
66 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:
...
4
votes
2answers
218 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 ...
3
votes
2answers
387 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" ...
4
votes
2answers
613 views
Splitting an array of numbers into all possible combinations
This takes an array of numbers then splits it into all possible combinations of the number array of size 4 then in another array puts the leftovers. As I want to take the difference in averages of ...