Why is dictionary.keys() a list and not a set?

Christoph Zwerschke cito at online.de
Thu Nov 24 11:33:42 EST 2005


jepler at unpythonic.net schrieb:
> You can already get a set from a dictionary's keys in an efficient manner:
>>>>l = dict.fromkeys(range(10))
>>>>set(l)
> Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

Good point. I expected that set(l) = set(l.items()) and not 
set(l.keys()), but the latter would not work with mutable values. See 
discussion with Martin.

-- Christoph



More information about the Python-list mailing list