How do I reverse a part (slice) of a list in Python?

前端 未结 7 771
灰色年华
灰色年华 2020-11-27 19:32

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         


        
7条回答
提交回复
热议问题