On 12/8/2014 9:50 PM, Steven D'Aprano wrote:
Roy Smith wrote:
Chris Angelico wrote:
def myzip(*args):
iters = map(iter, args)
while iters:
res = [next(i) for i in iters]
yield tuple(res)
Ugh. When I see "while foo", my brain says, "OK, you're about to see a
loop which is controlled by the value of foo being changed inside the
loop".
Yes. Me too. 99% of the time when you see "while foo", that's what you'll
get, so it's the safe assumption. But it's only an assumption, not a
requirement. When you read a bit more of the code and see that iters isn't
being modified, your reaction ought to be closer "oh wow, that's neat"
To me it is a code smell. iters is empty if and only if args is empty.
If args is empty, iters should not be created.
if args:
iters = ...
while True
... (return on exception)
makes the logic clear.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list