178RE: [python-iter] My needs are small
- Mar 13, 2001[Raymond Hettinger]
> For Python 2.2, can we agree to a miminal proposal:+1 here. Curiously, the Icon language defined iteration over (its flavor of)
> for key in dict:
> if key in dict:
dicts to return the values, not the keys. This struck me as unbearably
clumsy the first time I used it, and every time thereafter: if Icon had
given me the keys, I could easily get the corresponding values myself, but
with just the value in hand there was no clue as to the corresponding key.
A year or so later I read a piece by Ralph Griswold (Icon's father), in which
he identified this very behavior as one of Icon's design flaws, and the
language eventually grew a new builtin to let you generate the keys instead.
Now, with that story in mind, what
for blah in dict:
does may not be obvious to someone who just got in from Pluto, but it will be
hard to forget once learned.
if blah in dict:
is easy to remember too because it's another way to spell .has_key() <wink>.
there's-only-two-ways-to-do-it-ly y'rs - tim
- << Previous post in topic