slice notation as values?
steven.bethard at gmail.com
Sat Dec 10 15:58:29 CET 2005
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 key in tree.iterkeys('a','b')
> But the way default arguments work, prevents you from having
> this work in an analague way as a slice.
How so? Can't you just pass the *args to the slice contstructor? E.g.::
def iterkeys(self, *args):
keyslice = slice(*args)
Then you can use the slice object just as you would have otherwise.
More information about the Python-list