array alice of [:-0] ?? | |
Beginner question! :-)
x=[1,2,3,4]
for i in range(len(x)):
print x[:-i] Quote: Quote: Quote:
>>[]
>>[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] -[]
2) how then should one do this basic left-recursive subsetting (easily).
Thanks.
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- | | | | re: array alice of [:-0] ??
On 18/07/2006 11:17 PM, guthrie wrote: Quote:
Beginner question! :-)
>
x=[1,2,3,4]
for i in range(len(x)):
print x[:-i]
> Quote: Quote:
>>[]
>>[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] -[]
2) how then should one do this basic left-recursive subsetting (easily).
>
>
|>for i in range(len(x), -1, -1):
.... print x[:i]
....
[1, 2, 3, 4]
[1, 2, 3]
[1, 2]
[1]
[] | | | | re: array alice of [:-0] ??
guthrie wrote: Quote:
Beginner question! :-)
>
x=[1,2,3,4]
for i in range(len(x)):
print x[:-i]
> Quote: Quote:
>>[]
>>[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. Quote:
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. | | | | re: array alice of [:-0] ??
On 2006-07-18, guthrie <guthrie@mum.eduwrote: Quote:
Beginner question! :-)
>
x=[1,2,3,4]
for i in range(len(x)):
print x[:-i]
> Quote: Quote:
>[]
>[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 is correct. Negative indexes are a handy shorthand, but
they can give unexpected/strange results in a number of cases. Quote:
2) how then should one do this basic left-recursive subsetting (easily).
x=[1,2,3,4]
lng = len(x)
for i in range(lng):
print x[:lng-i]
--
Antoon Pardon | | | | re: array alice of [:-0] ??
Thanks all!!
---------------------
guthrie wrote: Quote:
Beginner question! :-)
>
x=[1,2,3,4]
for i in range(len(x)):
print x[:-i]
> Quote: Quote:
>>[]
>>[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] -[]
2) how then should one do this basic left-recursive subsetting (easily).
>
Thanks.
>
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|