Sets Module Bug?

Irmen de Jong irmen at -nospam-remove-this-xs4all.nl
Mon Aug 2 12:09:01 CEST 2004


Chris S. wrote:
>  >>> from sets import *
>  >>> Set((1,2,3))
> Set([1, 2, 3])
>  >>> Set([1,2,3])
> Set([1, 2, 3])
>  >>> Set(([1,2,3],[4,5,6]))
> Traceback (most recent call last):
>   File "<input>", line 1, in ?
>   File "sets.py", line 399, in __init__
>     self._update(iterable)
>   File "sets.py", line 344, in _update
>     data[element] = value
> TypeError: list objects are unhashable
> 
> How can a Set using a tuple or list be ok, but not a tuple of lists?

Because "list objects are unhashable", as Python told you :-)
AFAIK the sets module is built upon the dict type, it uses (requires)
the elements of the set to be hashable for efficient containment tests.
The library reference of the sets module also says:
"All of the elements in iterable should be immutable or be transformable to an immutable 
using the protocol described in section 5.13.3. "

--Irmen



More information about the Python-list mailing list