Re: [Tutor] string reversal using [::-1]

2017-06-12 Thread Alan Gauld via Tutor
On 12/06/17 15:57, Vikas YADAV wrote: > for i in range(len(s)-1, 1, -2): > print s[i] > - > > So my question is: how would you write "s[::-1]" in terms of a for loop for > illustration purpose? Exactly as above but replace -2 with -1 for i in

Re: [Tutor] string reversal using [::-1]

2017-06-12 Thread Vikas YADAV
om] Sent: Monday, June 12, 2017 1:26 AM To: Vikas YADAV <vik...@gmail.com> Cc: tutor <tutor@python.org> Subject: Re: [Tutor] string reversal using [::-1] [QUOTED ENTIRELY FROM STEVE {st...@pearwood.info} IN ANSWER TO A SLICING QUESTION] The way to think about string indexing and sli

Re: [Tutor] string reversal using [::-1]

2017-06-12 Thread Abdur-Rahmaan Janhangeer
[QUOTED ENTIRELY FROM STEVE {st...@pearwood.info} IN ANSWER TO A SLICING QUESTION] The way to think about string indexing and slicing is that the index positions mark *between* the characters. Take your string: Machine learning is awesome! For brevity, I'll just use the first word:

Re: [Tutor] string reversal using [::-1]

2017-06-11 Thread Peter Otten
Vikas YADAV wrote: > Question: Why does "123"[::-1] result in "321"? > > > > MY thinking is [::-1] is same as [0:3:-1], that the empty places defaults > to start and end index of the string object. > > So, if we start from 0 index and decrement index by 1 till we reach 3, how > many index we

Re: [Tutor] string reversal using [::-1]

2017-06-10 Thread Alan Gauld via Tutor
On 10/06/17 17:39, Vikas YADAV wrote: > Question: Why does "123"[::-1] result in "321"? > > MY thinking is [::-1] is same as [0:3:-1], that the empty places defaults to > start and end index of the string object. Did you try that? You may be surprised. The wonderful thing about the >>> prompt is

[Tutor] string reversal using [::-1]

2017-06-10 Thread Vikas YADAV
Question: Why does "123"[::-1] result in "321"? MY thinking is [::-1] is same as [0:3:-1], that the empty places defaults to start and end index of the string object. So, if we start from 0 index and decrement index by 1 till we reach 3, how many index we should get? I think we should get