[Python-Dev] Re: Sets: elt in dict, lst.include

Thomas Wouters thomas@xs4all.net
Wed, 24 Jan 2001 00:38:14 +0100


On Tue, Jan 23, 2001 at 03:38:39PM -0500, Eric S. Raymond wrote:

> > The only change that needs to be made to support sets of immutable
> > elements is to provide "in" on dictionaries.  The rest is then all
> > quite natural:

> >     dict[key] = 1
> >     if key in dict: ...
> >     for key in dict: ...

> Independently of implementation issues about sets, I think this is a
> damn fine idea. +1.

It's come up before. The problem with it is that it's not quite obvious
whether it is 'if key in dict' or 'if value in dict'. Sure, from the above
example it's obvious what you *expect*, but I suspect that 'for x in dict'
will result in a 40/60 split in expectations, and like American voters, the
20% middle section will change their vote each recount :-)

Now, if only there was a terribly obvious way to spell it... so that it's
immediately obvious which of the two you wanted.... something like, oh, I
donno, this, maybe:

  if key in dict.keys: ...
  if value in dict.values: ...

Ponder-ponder--Guido-should-use-the-time-machine-for-this-one!-ly y'rs,
-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!