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
> 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
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
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
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
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]
>
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
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
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
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
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
11 matches
Mail list logo