Re: Loop with else clause

2019-02-09 Thread DL Neil
Possibly the final contribution:- On 9/02/19 1:30 AM, Adriaan Renting wrote: Wow, you dug deep. =Thank you. It started to 'bug' me, so I really was 'scratching an itch'! My example was the reverse of the "toy example"'s you mention as I find that often code becomes much clearer if you

Re: Loop with else clause

2019-02-08 Thread Adriaan Renting
Wow, you dug deep. My example was the reverse of the "toy example"'s you mention as I find that often code becomes much clearer if you order it such that specific cases, sanity checking and exceptions go first, and then the default case at the end. So my general suggestion would be to handle

Re: Loop with else clause

2019-02-07 Thread DL Neil
Further to our discussion of how to improve a code review's discovery of the mistaken handling of a for...else... construct:- Yesterday was a national holiday, but today gave some opportunity to research. Way back in 2009 there was spirited discussion over on the Python Ideas list (warning,

Re: Loop with Else Clause

2019-02-05 Thread Christman, Roger Graydon
-Original Message- From: Python-list On Behalf Of DL Neil Sent: Monday, February 4, 2019 11:29 PM To: 'Python' Subject: Loop with else clause What is the pythonic way to handle the situation where if a condition exists the loop should be executed, but if it does not something else

RE: Loop with else clause

2019-02-05 Thread Avi Gross
The topic is how to deal with a python loop that may not be run if you want something else to happen in that case. Multiple solutions are presented along with this request: > Is there another, more pythonic, approach to conditional (for/while) > loop processing? Has anyone considered looking at

Re: Loop with else clause

2019-02-05 Thread Adriaan Renting
I don't know if it is very Pythonic, but I would do something like if no_oscar_nominees: print ("Sorry ...") else: print_list_of_oscar_nominees() And yes, that for/else construct can be confusing. Adriaan. >>> On 5-2-2019 at 5:29, DL Neil wrote: > What is the pythonic way to

RE: Loop with else clause

2019-02-05 Thread David Raymond
Of Peter Otten Sent: Tuesday, February 05, 2019 3:44 AM To: python-list@python.org Subject: Re: Loop with else clause DL Neil wrote: > What is the pythonic way to handle the situation where if a condition > exists the loop should be executed, but if it does not something else > s

Re: Loop with else clause

2019-02-05 Thread Peter Otten
DL Neil wrote: > What is the pythonic way to handle the situation where if a condition > exists the loop should be executed, but if it does not something else > should be done? > Possible solution: > To make anything more than the trivial case readable, I think I'd put > the list processing into

Re: Loop with else clause

2019-02-05 Thread Ben Finney
DL Neil writes: > Possible solution: > To make anything more than the trivial case readable, I think I'd put > the list processing into one function, and the exception into another > (except that this case is so trivial), ie > > if list: > process_list() #the heading and

Re: Loop with else clause

2019-02-04 Thread DL Neil
... = Footnote: Zamboni locks up after running into large patch of loose teeth. -Original Message- From: Python-list On Behalf Of DL Neil Sent: Monday, February 4, 2019 11:29 PM To: 'Python' Subject: Loop with else clause What is the pythonic way to handle the situation where

RE: Loop with else clause

2019-02-04 Thread Steve
Would it be a hyphythonitical question? = Footnote: Zamboni locks up after running into large patch of loose teeth. -Original Message- From: Python-list On Behalf Of DL Neil Sent: Monday, February 4, 2019 11:29 PM To: 'Python' Subject: Loop with else clause What

Loop with else clause

2019-02-04 Thread DL Neil
What is the pythonic way to handle the situation where if a condition exists the loop should be executed, but if it does not something else should be done? Why am I asking? Today's code review included a for...else structure. I've rarely seen such a thing, and even knowing it exists, cannot