Re: [Tutor] slicing a string

2010-09-08 Thread Sandip Bhattacharya
On Thu, Sep 9, 2010 at 11:34 AM, Evert Rol wrote: > Read > http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange > , note 5 (about one "page" down), which explicitly says "If i or j are > omitted or None, they become “end” values (which end depends on the

Re: [Tutor] slicing a string

2010-09-08 Thread Evert Rol
>> But remember that you can make it simpler if you simply don't specify >> the start and end points: >> > 'hello'[::-1] >> 'olleh' >> > > While I know that idiom works, I haven't really found an explanation > as to *why* it works that way. > > For a string S: > * Using range, you need ran

Re: [Tutor] slicing a string

2010-09-08 Thread Sandip Bhattacharya
On Tue, Sep 7, 2010 at 1:49 PM, Roel Schroeven wrote: > > But remember that you can make it simpler if you simply don't specify > the start and end points: > 'hello'[::-1] > 'olleh' > While I know that idiom works, I haven't really found an explanation as to *why* it works that way. For a s

Re: [Tutor] slicing a string

2010-09-07 Thread lists
>>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >>> doesn't work (as I expected it to) but that mytext[::-1] does. >>> >>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't >>> work? >> >> It does work. >> But remember that slices give you the first item to one le

Re: [Tutor] slicing a string

2010-09-07 Thread Roel Schroeven
Op 2010-09-07 0:43, Alan Gauld schreef: > > "lists" wrote > >> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >> doesn't work (as I expected it to) but that mytext[::-1] does. >> >> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't >> work? > > It does work. > B

Re: [Tutor] slicing a string

2010-09-06 Thread Andre Engels
On Tue, Sep 7, 2010 at 12:44 AM, lists wrote: >>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >>> doesn't work (as I expected it to) but that mytext[::-1] does. >>> >>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? >> >> How does it not "work"? What did

Re: [Tutor] slicing a string

2010-09-06 Thread Steven D'Aprano
On Tue, 7 Sep 2010 08:14:59 am lists wrote: > Hi guys, > > Continuing my Python learning, I came across an exercise which asks > me to take a string and reverse it. > > I understand that there is a function to do this i.e mytext.reverse() You understand wrong :) There is a function reversed() whi

Re: [Tutor] slicing a string

2010-09-06 Thread lists
>>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >>> doesn't work (as I expected it to) but that mytext[::-1] does. >>> >>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? >> >> How does it not "work"? What did you expect to happen? What did it do >> inste

Re: [Tutor] slicing a string

2010-09-06 Thread lists
>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >> doesn't work (as I expected it to) but that mytext[::-1] does. >> >> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? > > How does it not "work"? What did you expect to happen? What did it do instead? > > Gr

Re: [Tutor] slicing a string

2010-09-06 Thread Alan Gauld
"lists" wrote Assuming that mytext is "test", I've found that mytext[-1:-4:-1] doesn't work (as I expected it to) but that mytext[::-1] does. While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? It does work. But remember that slices give you the first item to one less tha

Re: [Tutor] slicing a string

2010-09-06 Thread Sander Sweers
On 7 September 2010 00:14, lists wrote: > Assuming that mytext is "test", I've found that mytext[-1:-4:-1] > doesn't work (as I expected it to) but that mytext[::-1] does. > > While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? How does it not "work"? What did you expect to happ

[Tutor] slicing a string

2010-09-06 Thread lists
Hi guys, Continuing my Python learning, I came across an exercise which asks me to take a string and reverse it. I understand that there is a function to do this i.e mytext.reverse() I imagine that the exercise author would rather I did this the hard way however. ;-) Assuming that mytext is "te