Loading ...
Sorry, an error occurred while loading the content.

178RE: [python-iter] My needs are small

Expand Messages
  • Tim Peters
    Mar 13, 2001
    • 0 Attachment
      [Raymond Hettinger]
      > For Python 2.2, can we agree to a miminal proposal:
      > for key in dict:
      > if key in dict:

      +1 here. Curiously, the Icon language defined iteration over (its flavor of)
      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
    • Show all 8 messages in this topic