Help with sets

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Mon Oct 11 13:11:03 CEST 2010

In message <8h9ob9FkurU1 at>, Gregory Ewing wrote:

> Lawrence D'Oliveiro wrote:
>> Did you know that applying the “set” or “frozenset” functions to a dict
>> return a set of its keys?
>> Seems a bit dodgy, somehow.
> That's just a consequence of the fact that dicts produce their
> keys when iterated over, and the set constructor iterates over
> whatever you give it.

Hmm. It seems that “iter(<dict>)” iterating over the keys has been around a 
long time. But a dict has both keys and values: why are language constructs 
treating them so specially as to grab the keys and throw away the values?

Is this an artifact of older directions in the language evolution, before 
sets were introduced?

More information about the Python-list mailing list