Why doesn\'t this work?
# to reverse a part of the string in place
a = [1,2,3,4,5]
a[2:4] = reversed(a[2:4]) # This works!
a[2:4] = [0,0] # Thi
Here's a weird example and weirder solution using slicing and a bit of list fundamentals.
Problem: Reverse a list in parts of two.
I/P : [1,2,3,4,5,6]
O/P: [3,2,1,6,5,4]
Soln:
[item for i in range(0,len(l),len(l)/2) for item in l[i:i+len(l)/2][::-1]]
Problem: Reverse the letters of someones name.
E.g Harry Porter
O/p: yrraH retroP
Soln:
' '.join(map(lambda x:x[::-1], s.split()))