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] # This works too. a[2:4].reverse() # But this doesn't work
Just use the slice and reverse it.
a[2:4] = a[2:4][::-1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With