[Python-Dev] Getting values stored inside sets

Antoine Pitrou solipsis at pitrou.net
Fri Apr 3 17:07:28 CEST 2009


Steven D'Aprano <steve <at> pearwood.info> writes:
> 
> That's hardly unusual in Python.
> 
> >>> alist = [0, 1, 2, 3, 4]
> >>> 3.0 in alist
> True
> >>> alist[3.0]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: list indices must be integers

Your example is wrong:

>>> alist = [0, 1, 2, 3, 4]
>>> alist.index(3.0)
3
>>> alist[alist.index(3.0)]
3

Regards

Antoine.




More information about the Python-Dev mailing list