array alice of [:-0] ??

Boris Borcic bborcic at gmail.com
Tue Jul 18 09:25:24 EDT 2006


guthrie wrote:
> Beginner question! :-)
> 
> x=[1,2,3,4]
> for i in range(len(x)):
>    print x[:-i]
> 
>  >>> []
>  >>> [1,2,3]
>  >>> [1,2]
>  >>> [1]
> 
> 1) The x[:-0] result seems inconsistent to me;
>     I get the idea that -0=0, so it is taken as x[:0] -> []

that's what you get.

> 2) how then should one do this basic left-recursive subsetting (easily).

I am not sure what you mean, but replacing x[:-i] by x[:len(x)-i] you will get 
continuous behavior at i==0.



More information about the Python-list mailing list