Re: invert the order of a string

2006-02-13 Thread Carl Cerecke
Eric McGraw wrote: >>Well, it turns out to be the best way to invert a string, IMO. The >>reversed() feature returns a reversed object... not a reversed string. >>In short, I have to fool with it again _after_ it has been inverted. The >>slicing takes care of the job right away and gives me what I

Re: invert the order of a string

2006-02-13 Thread Eric McGraw
> Well, it turns out to be the best way to invert a string, IMO. The > reversed() feature returns a reversed object... not a reversed string. > In short, I have to fool with it again _after_ it has been inverted. The > slicing takes care of the job right away and gives me what I want... no > Comput

Re: invert the order of a string

2006-02-13 Thread Paul Rubin
rtilley <[EMAIL PROTECTED]> writes: > Well, it turns out to be the best way to invert a string, IMO. The > reversed() feature returns a reversed object... not a reversed > string. In short, I have to fool with it again _after_ it has been > inverted. The slicing takes care of the job right away and

Re: invert the order of a string

2006-02-13 Thread Bruno Desthuilliers
Paul Rubin a écrit : > rtilley <[EMAIL PROTECTED]> writes: > >>s = list('some_random_string') >>print s >>s.reverse() >>print s >>s = ''.join(s) >>print s >> >>Surely there's a better way to do this, right? > > > In Python 2.4, just say > s = reversed('some_random_string') Python 2.4.1 (#1, J

Re: invert the order of a string

2006-02-13 Thread Bruno Desthuilliers
rtilley a écrit : > s = list('some_random_string') > print s > s.reverse() > print s > s = ''.join(s) > print s > > Surely there's a better way to do this, right? print 'some_random_string'[::-1] -- http://mail.python.org/mailman/listinfo/python-list

Re: invert the order of a string

2006-02-13 Thread rtilley
Dave Hansen wrote: > It's just simple slicing. Well, maybe not so simple, or at least not > so common, but with a syntax similar to the range function. Consider > the following (string chosen to make it obvious what's going on): > > s = "0123456789" > s[::] > s[3::] > s[:3:] > s[::3] > s[::-2] >

Re: invert the order of a string

2006-02-13 Thread Dave Hansen
On Mon, 13 Feb 2006 19:03:32 + in comp.lang.python, rtilley <[EMAIL PROTECTED]> wrote: >Dave Hansen wrote: >> How about >> >> s = "some random string" >> print s >> s = s[::-1] >> print s > >That looks like Perl, but it works. Makes me wonder with the string >module doesn't have a reverse o

Re: invert the order of a string

2006-02-13 Thread Paul Rubin
rtilley <[EMAIL PROTECTED]> writes: > s = list('some_random_string') > print s > s.reverse() > print s > s = ''.join(s) > print s > > Surely there's a better way to do this, right? In Python 2.4, just say s = reversed('some_random_string') -- http://mail.python.org/mailman/listinfo/python-list

Re: invert the order of a string

2006-02-13 Thread rtilley
Dave Hansen wrote: > How about > > s = "some random string" > print s > s = s[::-1] > print s That looks like Perl, but it works. Makes me wonder with the string module doesn't have a reverse or invert function? -- http://mail.python.org/mailman/listinfo/python-list

Re: invert the order of a string

2006-02-13 Thread Dave Hansen
On Mon, 13 Feb 2006 18:51:11 + in comp.lang.python, rtilley <[EMAIL PROTECTED]> wrote: >s = list('some_random_string') >print s >s.reverse() >print s >s = ''.join(s) >print s > >Surely there's a better way to do this, right? How about s = "some random string" print s s = s[::-1] print s HT

invert the order of a string

2006-02-13 Thread rtilley
s = list('some_random_string') print s s.reverse() print s s = ''.join(s) print s Surely there's a better way to do this, right? -- http://mail.python.org/mailman/listinfo/python-list