Set literals

simon at arrowtheory.com simon at arrowtheory.com
Mon Mar 21 19:01:10 EST 2005


+1 from me.

The other possible meaning for {1,2,3} would be {1:None,2:None,3:None},
but that is usually meant to be a set anyway (done with a dict).

So what is this: {1:2, 3, 4 } (apart from "nearly useless") ?

hmmm, thinking a bit more about this, it seems
you can build a set from a dict's keys, but not the other
way around. Is this odd, or what ?

>>> a = set({1:0,2:0,3:0})
>>> a
set([1, 2, 3])
>>>
>>> dict(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: cannot convert dictionary update sequence element #0 to a
sequence

Simon.




More information about the Python-list mailing list