Python 3: range objects cannot be sliced

Paul Rubin http
Fri Jan 16 13:15:42 EST 2009


Alan G Isaac <alan.isaac at gmail.com> writes:
>  >>> x = range(20)
>  >>> s = slice(None,None,2)
>  >>> x[s]
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: sequence index must be integer, not 'slice'

range is an iterator now.  Try itertools.islice.



More information about the Python-list mailing list