Skip to content

Instantly share code, notes, and snippets.

@yuchen-xue
Created August 12, 2018 07:42
Show Gist options
  • Save yuchen-xue/9f1a7489d4829f4ba12e7912f49714bb to your computer and use it in GitHub Desktop.
Save yuchen-xue/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