Skip to content

Instantly share code, notes, and snippets.

@SeanSyue
Created August 12, 2018 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanSyue/9f1a7489d4829f4ba12e7912f49714bb to your computer and use it in GitHub Desktop.
Save SeanSyue/9f1a7489d4829f4ba12e7912f49714bb to your computer and use it in GitHub Desktop.
Combine `zip()` and `sorted()` to get a new long sorted list.
list1 = [3, 2, 4, 1, 1]
list2 = ['three', 'two', 'four', 'one', 'one2']
zipped = zip(list1, list2) # zip two lists
sorted_zip = sorted(zipped) # sort
sorted_zip_comb = zip(*sorted_zip) # unzip, then zip again
print(list(sorted_zip_comb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment