[Tutor] reversing a string

Simon Brunning SBrunning@trisystems.co.uk
Tue, 3 Jul 2001 08:43:13 +0100


> From:	Praveen Pathiyil [SMTP:ppathiyi@cisco.com]
>          Is there any methods in string module or any builtin functions to
> reverse a string ?  I am using Python 1.5.2
>   
Nothing built in that I know of, but it's pretty simple. Try the following
(untested):

import string

def reversestring(inString):
    letters = list(inString)
    letters.reverse()
    return string.join(letters, '')

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.