Mike Meyer wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > Christoph Zwerschke wrote: > >> [EMAIL PROTECTED] 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. > > puzzled. items() return tuples which I believe can be element of set ? > > Or I misread you ? > > Not all tuples can be elements of a set. Elements of a set have to be > hashable. Tuples compute their hash by hashing their contents. If > their contents aren't hashable, the tuple isn't hashable, and hence > can't be an element of a set. If the values in the dictionary aren't > hashable, then the tuples returned by items() won't be hashable > either, and hence can't be elements of a set. > ah, thanks. I was thinking that tuples being immutable object must be hashable. So it is not about mutable but hashable.
-- http://mail.python.org/mailman/listinfo/python-list