Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将列表中的项目向下移动两个单位?
前任。将数字“1”向下移动两个单位。
>>> move([1,2,3,4]) [2,3,1,4]
正如 sweeneyrod 指出的不需要切片:
def move (l, from_, to = 2): return l.insert (to, l.pop (from_) )