Advertisement
here2share

# swapsort_list_a_via_list_b_by_index.py

May 9th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. # swapsort_list_a_via_list_b_by_index.py ### generic version
  2.  
  3. import random
  4. val = [9,8,7,6,5,4,3,2,1]
  5. cue = ['a', 1, 'b', 'c', 2, 3, 'd', 'e', 'f', 4]
  6.  
  7.  
  8. def swap():
  9.     swap=[]
  10.     for z in range(len(cue)):
  11.         if cue[z] in val:
  12.             swap.append([val.index(cue[z]),cue[z]])
  13.             cue[z]=''
  14.     swap = [z[1] for z in sorted(swap)]
  15.     for z in swap:
  16.         cue[cue.index('')]=z
  17.     return cue
  18. #
  19.  
  20. print swap()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement