Slices... what are they good for?
Paul Moore
gustav at morpheus.demon.co.uk
Thu Mar 21 14:11:51 EST 2002
On 20 Mar 2002 16:03:51 -0800, johnl at axis.com.au (John Lehmann) wrote:
>I had forgotted slices existed, until I was making an object that I
>was pretending was a tuple.
>
>I was shocked to find that this didn't work:
>
>>>> l = ['a', 'b', 'c']
>>>> l[1:2]
>'b'
>>>> l[ slice(1,2) ]
>Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
>TypeError: sequence index must be integer
It strikes me as a definite wart that the builtin types don't support
generalised slices. Of course, adding such support is seriously
non-trivial, which is probably why it hasn't happened up to now (and
maybe never will...)
Paul.
More information about the Python-list
mailing list