Re: slice notation as values?

2005-12-12 Thread Antoon Pardon
Op 2005-12-10, Devan L schreef [EMAIL PROTECTED]: Antoon Pardon wrote: On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: [snip] I also think that other functions could benefit. For instance suppose you want to iterate over every second element in a list. Sure you can use an extended

Re: slice notation as values?

2005-12-12 Thread Antoon Pardon
Op 2005-12-10, Brian Beck schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Will it ever be possible to write things like: a = 4:9 I made a silly recipe to do something like this a while ago, not that I'd recommend using it. But I also think it wouldn't be too far-fetched to allow slice

Re: slice notation as values?

2005-12-12 Thread Antoon Pardon
Op 2005-12-11, Bengt Richter schreef [EMAIL PROTECTED]: On 10 Dec 2005 12:07:12 -0800, Devan L [EMAIL PROTECTED] wrote: Antoon Pardon wrote: On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: [snip] I also think that other functions could benefit. For instance suppose you want to iterate

Re: slice notation as values?

2005-12-12 Thread bonono
Antoon Pardon wrote: Suppose I have a list with 10 000 elements and I want the sum of the first 100, the sum of the second 100 ... One way to do that would be: for i in xrange(0,1,100): sum(itertools.islice(lst, i, i+100)) But itertools.islice would each time start from the

Re: slice notation as values?

2005-12-12 Thread Bengt Richter
On 12 Dec 2005 08:34:37 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-12-10, Devan L schreef [EMAIL PROTECTED]: Antoon Pardon wrote: On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: [snip] I also think that other functions could benefit. For instance suppose you want to iterate

Re: slice notation as values?

2005-12-12 Thread Antoon Pardon
Op 2005-12-12, Bengt Richter schreef [EMAIL PROTECTED]: On 12 Dec 2005 08:34:37 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-12-10, Devan L schreef [EMAIL PROTECTED]: Antoon Pardon wrote: On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: [snip] I also think that other functions

Re: slice notation as values?

2005-12-11 Thread Duncan Booth
Brian Beck wrote: Antoon Pardon wrote: Will it ever be possible to write things like: a = 4:9 I made a silly recipe to do something like this a while ago, not that I'd recommend using it. But I also think it wouldn't be too far-fetched to allow slice creation using a syntax like the

Re: slice notation as values?

2005-12-10 Thread Antoon Pardon
On 2005-12-09, Duncan Booth [EMAIL PROTECTED] wrote: Antoon Pardon wrote: If the user can write for key in tree['a':'b']: then he can write: for key in tree['a':'b'].iteritems(): No he can't. tree['a':'b'] would provide a list of keys that all start with an 'a'. Such a list

Re: slice notation as values?

2005-12-10 Thread Steven Bethard
Antoon Pardon wrote: So lets agree that tree['a':'b'] would produce a subtree. Then I still would prefer the possibility to do something like: for key in tree.iterkeys('a':'b') Instead of having to write for key in tree['a':'b'].iterkeys() Sure I can now do it like this: for

Re: slice notation as values?

2005-12-10 Thread Duncan Booth
Antoon Pardon wrote: In general I use slices over a tree because I only want to iterate over a specific subdomain of the keys. I'm not iterested in make a tree over the subdomain. Making such a subtree would be an enormous waste of resources. Probably not unless you have really large data

Re: slice notation as values?

2005-12-10 Thread Antoon Pardon
On 2005-12-10, Steven Bethard [EMAIL PROTECTED] wrote: Antoon Pardon wrote: So lets agree that tree['a':'b'] would produce a subtree. Then I still would prefer the possibility to do something like: for key in tree.iterkeys('a':'b') Instead of having to write for key in

Re: slice notation as values?

2005-12-10 Thread Antoon Pardon
On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: Antoon Pardon wrote: In general I use slices over a tree because I only want to iterate over a specific subdomain of the keys. I'm not iterested in make a tree over the subdomain. Making such a subtree would be an enormous waste of

Re: slice notation as values?

2005-12-10 Thread Devan L
Antoon Pardon wrote: On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: [snip] I also think that other functions could benefit. For instance suppose you want to iterate over every second element in a list. Sure you can use an extended slice or use some kind of while. But why not extend

Re: slice notation as values?

2005-12-10 Thread Brian Beck
Antoon Pardon wrote: Will it ever be possible to write things like: a = 4:9 I made a silly recipe to do something like this a while ago, not that I'd recommend using it. But I also think it wouldn't be too far-fetched to allow slice creation using a syntax like the above...

Re: slice notation as values?

2005-12-10 Thread Steven Bethard
Antoon Pardon wrote: On 2005-12-10, Steven Bethard [EMAIL PROTECTED] wrote: Antoon Pardon wrote: So lets agree that tree['a':'b'] would produce a subtree. Then I still would prefer the possibility to do something like: for key in tree.iterkeys('a':'b') Instead of having to write for key

Re: slice notation as values?

2005-12-10 Thread Bengt Richter
On 10 Dec 2005 12:07:12 -0800, Devan L [EMAIL PROTECTED] wrote: Antoon Pardon wrote: On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: [snip] I also think that other functions could benefit. For instance suppose you want to iterate over every second element in a list. Sure you can use

slice notation as values?

2005-12-09 Thread Antoon Pardon
Now slices are objects in python, I was wondering if slice notation will be usable outside subscribtion in the future. Will it ever be possible to write things like: a = 4:9 for key, value in tree.items('alfa.': 'beta.'): -- Antoon Pardon --

Re: slice notation as values?

2005-12-09 Thread Steve Holden
Antoon Pardon wrote: Now slices are objects in python, I was wondering if slice notation will be usable outside subscribtion in the future. Will it ever be possible to write things like: a = 4:9 for key, value in tree.items('alfa.': 'beta.'): Do you mean for key, value in

Re: slice notation as values?

2005-12-09 Thread Antoon Pardon
Op 2005-12-09, Steve Holden schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Now slices are objects in python, I was wondering if slice notation will be usable outside subscribtion in the future. Will it ever be possible to write things like: a = 4:9 for key, value in

Re: slice notation as values?

2005-12-09 Thread Duncan Booth
Antoon Pardon wrote: Will it ever be possible to write things like: a = 4:9 for key, value in tree.items('alfa.': 'beta.'): The first of these works fine, except you need to use the correct syntax: a = slice(4,9) range(10)[a] [4, 5, 6, 7, 8] The second also works fine, provide

Re: slice notation as values?

2005-12-09 Thread Antoon Pardon
Op 2005-12-09, Duncan Booth schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Will it ever be possible to write things like: a = 4:9 for key, value in tree.items('alfa.': 'beta.'): The first of these works fine, except you need to use the correct syntax: Sure, I know that. But why a

Re: slice notation as values?

2005-12-09 Thread Duncan Booth
Antoon Pardon asked: If we have lst = range(10), we can write lst[slice(3,7)] instead of lst[3:7] Now my impression is that should we only have the upper notation, slices would be less usefull, because it would make using them more cumbersome. Quite right, but the syntax for

Re: slice notation as values?

2005-12-09 Thread Antoon Pardon
Op 2005-12-09, Duncan Booth schreef [EMAIL PROTECTED]: Antoon Pardon asked: If we have lst = range(10), we can write lst[slice(3,7)] instead of lst[3:7] Now my impression is that should we only have the upper notation, slices would be less usefull, because it would make

Re: slice notation as values?

2005-12-09 Thread Duncan Booth
Antoon Pardon wrote: If the user can write for key in tree['a':'b']: then he can write: for key in tree['a':'b'].iteritems(): No he can't. tree['a':'b'] would provide a list of keys that all start with an 'a'. Such a list doesn't have an iteritems method. It wouldn't even