Set literal confusion

Peter Otten __peter__ at
Tue Sep 22 20:12:33 CEST 2009

Dennis Lee Bieber wrote:

> range() is what used to be xrange() -- an on-demand generator of
> values. You created a set containing a single generator. Try something
> like:
> 5 in {list(range(10))}

No. {expr} is always a set with a single element. 

>>> {range(10)}
{range(0, 10)}

That element cannot be a list, by the way, because lists aren't hashable.

>>> {list(range(10))}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'


More information about the Python-list mailing list