Last active
August 21, 2016 18:48
-
-
Save burakdede/b303d8e44074f1b4f8cf991eae3d8d75 to your computer and use it in GitHub Desktop.
positional itemgetter sort
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
""" | |
[('tr', 90), ('uk', 44), ('us', 1)] | |
[('us', 1), ('uk', 44), ('tr', 90)] | |
[('tr', 90), ('uk', 44), ('us', 1)] | |
""" | |
from operator import itemgetter | |
rows = [ | |
("tr", 90), | |
("us", 1), | |
("uk", 44) | |
] | |
by_country_name = sorted(rows, key=itemgetter(0)) | |
by_country_code = sorted(rows, key=itemgetter(1)) | |
by_both = sorted(rows, key=itemgetter(0,1)) | |
print(by_country_name) | |
print(by_country_code) | |
print(by_both) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment