473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

array alice of [:-0] ??

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
4 1104
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
11
by: James Stroud | last post by:
Hello, I am looking for a nice way to take only those charachters from a string that are in another string and make a new string: >>> astr = "Bob Carol Ted Alice" >>> letters = "adB" >>>...
17
by: Mark | last post by:
uhhmmm... not really sure how to word this. i cant get get this to compile.. i'm not sure what the proper syntax to do this is.. hopefully it's self explanatory. here's my class: ------ class...
20
by: Petter Reinholdtsen | last post by:
Is the code fragment 'char a = ("a");' valid ANSI C? The problematic part is '("a")'. I am sure 'char a = "a";' is valid ANSI C, but I am more unsure if it is allowed to place () around the...
5
by: CoreyWhite | last post by:
Here is my design to build a cyborg. You just have a search engine, and as the user types in queries to the cyborg, the program searches for the best possible responses. Then a support agent...
6
by: =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?= | last post by:
Morning, I've got an ASP.NET 2.0 Web Application. Behind it, I've a statically-scoped facade/class factory as the business layer, running atomic functions back and forth from my by DAL. The...
1
by: Aaron Watters | last post by:
Hi folks. Andy Pausch who headed up the Alice project which aims to teach 3D animation using Python has gained additional fame from his "last lecture" where he talks about being diagnosed with...
9
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.