What does "::" mean?

Michael Hoffman cam.ac.uk at mh391.invalid
Thu Jul 21 11:28:38 EDT 2005


Robert Kern wrote:
> Rob Williscroft wrote:
> 
>> import sys
>>
>> live = 'live'
>>
>> print live[ sys.maxint  :              : -1 ]
>> print live[ len(live)-1 :              : -1 ]
>>
>> print live[ len(live)-1 : -len(live)-1 : -1 ]
>> print live[ len(live)-1 : -sys.maxint  : -1 ]
>> print live[ sys.maxint  : -sys.maxint  : -1 ]
>> print live[ -1          : -len(live)-1 : -1 ]
>>
>> Of course there is only one obvious way to do it, but alas
>> as I'm not Dutch I can't tell which it is.
> 
> Well, that part's easy at least:
> 
>   live[::-1]
> 
> :-)  And so the circle is complete ...

What about reversed(live)? Or if you want a list instead of an iterator, 
list(reversed(live))?
-- 
Michael Hoffman



More information about the Python-list mailing list