On Wed, Nov 25, 2020 at 3:44 PM Steven D'Aprano <[email protected]> wrote:
> Obviously you can tell the two apart, so I'm confused by your comment.
>
What I imagined while reading Greg's comment was trying to explain to a
student why this didn't work the way they expected. "Ok, so in the first
case I'm *not* starting at the beginning? I'm starting in the
*middle??? *That
makes no sense."
forward = False
data = [1, 2, 3, 4]
if forward:
# Start at the beginning and count up.
idx = 0
step = 1
else:
# Start at the end and count down.
idx = len(data) - 1
step = -1
while True:
try:
print(data[idx])
except IndexError:
break
else:
idx += step
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/S7QJDCMSB7KWX5AYT5VJTUFVEHUMX5YF/
Code of Conduct: http://python.org/psf/codeofconduct/