Guest User

Untitled

a guest
Jan 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. i_xs = [(x, i) for (i, x) in enumerate(xs)]
  2. s = sorted(i_xs)
  3. sorted_xs, index_lst = unzip(s)
  4.  
  5. def unzip(ls):
  6. if isinstance(ls, list):
  7. if not ls:
  8. return [], []
  9. else:
  10. xs, ys = zip(*ls)
  11.  
  12. return list(xs), list(ys)
  13. else:
  14. raise TypeError
  15.  
  16. [34, 23424, 1212, -2324, 34353]
  17.  
  18. [-2324, 34, 1212, 23424, 34353]
  19.  
  20. [3, 0, 2, 1, 4]
Add Comment
Please, Sign In to add comment