invert or reverse a string... warning this is a rant

Paul McGuire ptmcg at austin.rr._bogus_.com
Thu Oct 19 13:03:42 EDT 2006


"Demel, Jeff" <Jeff.Demel at JavelinDirect.com> wrote in message 
news:mailman.764.1161275760.11739.python-list at python.org...
John Salerno wrote:
P.S.  How about a string.shuffle() method that splits the string in half
into two new strings str1 and str2, and then recompiles the string by
alternating one character from each str1 and str2 as it goes?  Like
shuffling cards.  ;)


You mean:

"".join(sum(map(list,zip(s,s[len(s)/2:])),[]))

perhaps?

>>> s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>>> "".join(sum(map(list,zip(s,s[len(s)/2:])),[]))
'ANBOCPDQERFSGTHUIVJWKXLYMZ'
>>>

-- Paul 





More information about the Python-list mailing list