[Tutor] Array slices in python with negative step

vishwajeet singh dextrous85 at gmail.com
Mon Jan 11 21:07:31 CET 2010


On Tue, Jan 12, 2010 at 1:16 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "vishwajeet singh" <dextrous85 at gmail.com> wrote
>
>  Thanks for your response but I am still not clear; can you show me the
>> equivalent of [::-1]  in terms actually specifying start-index, end-index
>> which gives me reverse of the given arrary.
>>
>
> I don't think you can, you must use the empty value.
>
> In theory you could use -1 except of course -1 refers to the 'e'...
>
> Its a slight anomoly due to the use of negative indexing. You
> can do:
>
> 'abcde'[0:5]
>
> and get the same as [0:]
>
> But you cannot put any valid value for x in
>
> 'abcde[4 : x :-1]
>
> that gets you the full string. You need to use [4::-1]
>
> HTH,
>
>
Thanks Alan and Micheal that surely cleard my doubts.


-- 
Vishwajeet Singh
+91-9657702154 | dextrous85 at gmail.com | http://singhvishwajeet.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
http://www.linkedin.com/in/singhvishwajeet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100112/856a39da/attachment-0001.htm>


More information about the Tutor mailing list