Newbie 1st program
Peter Otten
__peter__ at web.de
Tue Aug 17 06:57:29 EDT 2004
Nick Jacobson wrote:
> d = dict(zip(range(10), ary))
Magic constants are evil. The above will not (automatically) remain correct
when new items are added to ary. Therefore:
d = dict(enumerate(ary))
> i = event.GetInt()
> if i in range(10):
Make the above line
if i in d:
instead. Faster and more robust against changes elsewhere (no need for
consecutive integer keys).
You wouldn't want to teach a newbie bad habits, would you :-)
Peter
More information about the Python-list
mailing list