Created
August 12, 2018 07:42
-
-
Save yuchen-xue/9f1a7489d4829f4ba12e7912f49714bb to your computer and use it in GitHub Desktop.
Combine `zip()` and `sorted()` to get a new long sorted list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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