By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,539 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,539 IT Pros & Developers. It's quick & easy.

array alice of [:-0] ??

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 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 =----
Jul 18 '06 #1
Share this Question
Share on Google+
4 Replies


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 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]
[]
Jul 18 '06 #2

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 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.
Jul 18 '06 #3

P: n/a
On 2006-07-18, 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 left-recursive subsetting (easily).
x=[1,2,3,4]
lng = len(x)
for i in range(lng):
print x[:lng-i]

--
Antoon Pardon
Jul 18 '06 #4

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 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 =----
Jul 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.