-
-
Save ixtel/d5c9a632a9650b36c795 to your computer and use it in GitHub Desktop.
Sorting a list according to the first.
This file contains hidden or 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
from operator import itemgetter | |
names = ['a', 'c', 'd', 'b'] | |
runes = [1, 2, 3, 4] | |
def mixer(a, b): | |
""" | |
Returns the second list sorted according to the first | |
""" | |
return [z[1] for z in sorted(zip(a, b), key=itemgetter(0))] | |
print mixer(names, runes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment