Move an item inside a list?

前端 未结 6 517
-上瘾入骨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:36

    l = list(...)
    if item in l:
        l.remove(item) #  checks if the item to be moved is present in the list 
    l.insert(new_index,item)
    

提交回复
热议问题