Forgive me, I am new to python.
In other languages, When I want to iterate at the end of a loop, rather than at the beginning I'd use a do while
loop.
Python doesn't have a do while
so I have done this:
iter_ = zip(x_list, y_list)
x,y = initial_values()
while x:
foo(x,y)
x,y = next(iter_,(False,False))
This works fine, but I am not fully satisfied with:
- the default
(False,False)
tuple. However I find it preferable totry except: StopIteration; break
- the use of x as the condition, as x could be an element which would legitimately be interpreted as
False
in a logical test. However I find it preferable to introducing a separate condition variable and test in addition to thenext()
call
What is the best/most python idiomatic way to perform iteration at the end rather than the beginning of the loop?