P: n/a

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] []
2) how then should one do this basic leftrecursive subsetting (easily).
Thanks.
== Posted via Newsfeeds.Com  UnlimitedUnrestrictedSecure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
= East and WestCoast Server Farms  Total Privacy via Encryption =  
Share this Question
P: n/a

On 18/07/2006 11:17 PM, 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] []
2) how then should one do this basic leftrecursive subsetting (easily).
>for i in range(len(x), 1, 1):
.... print x[:i]
....
[1, 2, 3, 4]
[1, 2, 3]
[1, 2]
[1]
[]  
P: n/a

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 leftrecursive 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.  
P: n/a

On 20060718, guthrie <gu*****@mum.eduwrote:
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 is correct. Negative indexes are a handy shorthand, but
they can give unexpected/strange results in a number of cases.
2) how then should one do this basic leftrecursive subsetting (easily).
x=[1,2,3,4]
lng = len(x)
for i in range(lng):
print x[:lngi]

Antoon Pardon  
P: n/a

Thanks all!!

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] []
2) how then should one do this basic leftrecursive subsetting (easily).
Thanks.
== Posted via Newsfeeds.Com  UnlimitedUnrestrictedSecure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
= East and WestCoast Server Farms  Total Privacy via Encryption =   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 956
 replies: 4
 date asked: Jul 18 '06
