Skip to main content

All Questions

Tagged with
3 votes
4 answers
359 views

Reducing cyclomatic complexity of a state machine

I have a function (written in Python) that processes a loosely structured log file. The log file would have begin-end markers for different sections, with each section describing different things (e.g....
Happy Green Kid Naps's user avatar
-6 votes
1 answer
383 views

While loop definition in python

My question is about a use of while loops that seems very abstract to me. I understand a while loop like the first one (one which has a clearly defined statement): num = 1 while num<1: ...
stayghostly's user avatar
-1 votes
1 answer
408 views

How to read user input and at the same time execute periodic commands

How would I go about prompting user-input, while at the same time running timers, to periodically execute automatic functions. Pseudo-code to illustrate: while true { if input() OR timer(10) ...
Ciarán J. Hagen's user avatar
2 votes
2 answers
3k views

Efficiency considerations: nested loop vs recursion

I would consider myself an intermediate Python programmer. One of my recent challenges was creating a list of all possible solutions to a given Countdown problem. Without getting into too much detail,...
IliaK's user avatar
  • 23
1 vote
2 answers
115 views

Factored out loop control in Python

I have a for loop in python like this: for item in items: onwards = make_flow_decision(item) if onwards == 'break': break elif onwards == 'continue': continue elif ...
mlissner's user avatar
  • 131
2 votes
1 answer
606 views

Break big method into 2 methods, first containing a "for" loop and second a "break"

A method grew too big for its own good, and I need to break it up into two separate methods. def big_method(dct): # Initial code # ... for i in dct: # More code # ... ...
user's user avatar
  • 479
1 vote
1 answer
3k views

adding the digits of a number

I am trying to write a program that asks the user for a decimal number and then calculates the sum of its digits. for example if the number is 123.25 then the sum will be 1+2+3+2+5=13. I decided to ...
user170800's user avatar
1 vote
3 answers
137 views

Using higher order functions to apply m out of M filter's and then transform data of size n?

Total no: of filters possible is M . User can select m filters where m <= M . A typical example is files from a folder , he could say modified between so and so date , start with so and so and so ...
Nishant's user avatar
  • 575
84 votes
3 answers
43k views

How do I move away from the “for-loop” school of thought?

This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays ...
turnip's user avatar
  • 1,677
0 votes
1 answer
771 views

Python case statement? [duplicate]

I made a simple Python script that takes user input in order to generate a series of mathematical responses. In one part I did this: while True: And iterated through the loop until I used an if ...
Alex_adl04's user avatar
3 votes
1 answer
644 views

Will loop constructs become obsolete? [closed]

By loop constructs I mean for… and while… constructs with nested statements. Currently I am coding a tool in Python and decided out of curiosity not to use the regular loops - and rely on filter/map/...
Eugene's user avatar
  • 646
0 votes
1 answer
104 views

Code execution within delimiters [closed]

Is there any way I can execute a block of code in a loop, like so: [ some code goes here ] Where the delimiters are "[" and "]", and also allowing for nested blocks, i.e.: [the user can create ...
knight's user avatar
  • 111
7 votes
2 answers
14k views

Loop Invariants in Python

I have a bit of experience with loop invariants but I'm not really clear on them. I'm trying to learn them through an example in Python. Can someone point one out or help me understand? I've ...
recluze's user avatar
  • 269