Logo

Programming-Idioms

History of Idiom 41 > diff from v38 to v39

Edit summary for version 39 by programming-idioms.org:
[Python] Was wrong (didn't handle multi-byte)

Version 38

2018-01-03, 23:34:01

Version 39

2018-01-03, 23:44:30

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration
Code
t = s[::-1]
Code
t = s.decode('utf8')[::-1].encode('utf8')
Origin
http://stackoverflow.com/questions/931092/reverse-a-string-in-python/931095#931095
Origin
http://stackoverflow.com/questions/931092/reverse-a-string-in-python/931095#931095