slice notation as values?
duncan.booth at invalid.invalid
Fri Dec 9 16:00:11 CET 2005
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
> contain the information to construct items.
Why would it produce a list?
Slicing a *list* produces a list, slicing a tuple produces a tuple, slicing
a string produces a string. I would expect slicing any other type would
also return you a new object of the same type. Thats what the code sample I
posted earlier does.
More information about the Python-list