Advertisement
jon_mirow

A function to move list items.

Jul 11th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def move(frm, to, lst):
  2.     """
  3.    Moves an element in a list.
  4.    frm: index to move element from
  5.    to : index to move element to
  6.    lst: the list to be updated
  7.    """
  8.     if to < frm:
  9.         lst.insert(to, lst.pop(frm))
  10.     elif frm < to:
  11.         lst.insert(to+1, lst[frm])
  12.         lst.pop(frm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement