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

Ka-Ping Yee ping@lfw.org
Tue, 23 Jan 2001 19:29:24 -0800 (PST)


I wrote:
> The only change that needs to be made to support sets of immutable
> elements is to provide "in" on dictionaries.

Thomas Wouters wrote:
> 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'.

Yes, and i've seen this objection before, and i think it's silly.

> 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,

No way... it's at least 90/10.

How often do you write 'dict.has_key(x)'?          (std lib says: 206)
How often do you write 'for x in dict.keys()'?     (std lib says: 49)

How often do you write 'x in dict.values()'?       (std lib says: 0)
How often do you write 'for x in dict.values()'?   (std lib says: 3)

I rest my case.


-- ?!ng