[Tutor] Extended slicing applied to mapping objects (was What exactly is [::-1]?)

Bob Gailer bgailer at alum.rpi.edu
Thu Jul 26 22:51:00 CEST 2007


Bob Gailer wrote:
> Alan Gauld wrote:
>   
>> The ref manual ... for extended slicing says:
>>
>> ----------------------
>> The semantics for an extended slicing are as follows. The primary must
>> evaluate to a mapping object
>>     
> d = {}
>   
>> It is indexed with a key that is constructed from the slice list, as follows. 
>>     
> Note that (CORRECTION removed the html tags)
> slice_list ::= slice_item ("," slice_item)* [","]
> slice_item ::= expression | proper_slice  | ellipsis 
>
>   
>> If the slice list contains at least one comma, the key is a tuple containing the conversion of the slice items
>>     
> d[1,2] = 3
>   
>> otherwise, the conversion of the lone slice item is the key. 
>>     
> This is the usual application of a key where slice_item is an expression
>
> d[313] = 4
>   
>> The conversion of a slice item that is an expression is that expression. The conversion of an ellipsis slice item is the built-in Ellipsis object. 
>>     
> print d
> {(1, 2): 3, Ellipsis: 4, 313: 4}
>
> Now consider:
>
> slice_item 	::= 	expression <Booleans.html#tok-expression> | 
> proper_slice <slicings.html#tok-proper_slice> | ellipsis 
> <slicings.html#tok-ellipsis>
>
>
>
> We took care of the cases where slice_item is expression or ellipsis.
>
> How to apply a slice_list consisting of slice_item(s) that are 
> proper_slices to a mapping object???
>
>   


-- 
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC




More information about the Tutor mailing list