Countdown
Jeff Sandys
sandysj at asme.org
Thu Jun 22 18:37:33 EDT 2000
Python is really elegant when counting up:
for i in range(len(thing)):
print thing[i]
But when counting down looks ugly:
for j in range(len(thing)-1,-1,-1):
print thing[i]
Advice so far:
Stop doing things backwards:
(customer request)
Use reverse first:
(destructive, need to unreverse after)
Live with it:
(bytecode doesn't care, but it is still ugly)
Try range(len(thing)).reverse():
(doesn't work but):
rthing = range(len(thing))
rthing.reverse()
for k in rthing:
print thing[i]
(works, but also ugly)
More information about the Python-list
mailing list