Move an item inside a list?

前端 未结 6 506
-上瘾入骨i
-上瘾入骨i 2020-11-29 01:58

In Python, how do I move an item to a definite index in a list?

6条回答
  •  一整个雨季
    2020-11-29 02:35

    A solution very simple, but you have to know the index of the original position and the index of the new position:

    list1[index1],list1[index2]=list1[index2],list1[index1]
    

提交回复
热议问题