Swap slices of indexes using a function

后端 未结 2 974
一整个雨季
一整个雨季 2020-12-22 02:39

Follow-up question of: Python swap indexes using slices

r = [\'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\'] 

If I want to swap sli

2条回答
  •  生来不讨喜
    2020-12-22 03:29

    Without any calculation, you can do :

    def swap(r,a,b,c,d):
       assert a<=b<=c<=d  
       r[a:d]=r[c:d]+r[b:c]+r[a:b]
    

提交回复
热议问题