Initializing a set from a list

Robert Kern robert.kern at gmail.com
Wed Jun 21 08:11:51 CEST 2006


Xiaolei Li wrote:
> Hi,
> 
> I'm trying to initialize a set from a list but am unable to do so.  My
> list "c", looks like:
> 
> [(1.00909, 0.91969999999999996, -0.13550388182991072, 0),
> (0.87423999999999991, 0.6666700000000001, -0.21230487137222254, 0)]
> 
> So basically a list of 2 tuples, each with 4 elements.  Since tuples
> are immutable, I think a set should be able to support them.
> 
> Anyway, I then do:
> 
> set_c = set(c)
> 
> And instead of getting a set, I get "None" when I try to print out
> set_c.  len(set_c) complains "TypeError: len() of unsized object."
> Help?  

>>> c = [(1.00909, 0.91969999999999996, -0.13550388182991072, 0),
... (0.87423999999999991, 0.6666700000000001, -0.21230487137222254, 0)]
>>> set_c = set(c)
>>> set_c
set([(1.00909, 0.91969999999999996, -0.13550388182991072, 0),
(0.87423999999999991, 0.6666700000000001, -0.21230487137222254, 0)])
>>>

Please copy-and-paste the exact code that you wrote and the exact output.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list