Advertisement
here2share

# sort_list_of tuples.py

Apr 25th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # sort_list_of tuples.py
  2.  
  3. list1 = ["what", "I'm", "sorting", "by"]
  4. list2 = ["something", "else", "to", "sort"]
  5. pairs = map(None, list1, list2)
  6. print pairs
  7. #  [('what', 'something'), ("I'm", 'else'), ('sorting', 'to'), ('by', 'sort')]
  8. pairs.sort()
  9. print pairs
  10. #  [("I'm", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', 'something')]
  11. result = pairs[:]
  12. for i in xrange(len(result)): result[i] = result[i][1]
  13. print result
  14. #  ['else', 'sort', 'to', 'something']
  15. #  Note that "I'm" sorts before "by" because uppercase "I" comes before lowercase "b" in the ascii order.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement