-
-
Save ibeauregard/d9638591a0c56e5436301efc4b3419c5 to your computer and use it in GitHub Desktop.
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
from collections import namedtuple | |
Key = namedtuple('Key', ['index', 'ascending']) | |
keys = [Key(index=2, ascending=False), Key(index=0, ascending=True)] | |
def sort_key(row): | |
values = [] | |
for key in keys: | |
value = converted(row[key.index]) | |
values.append(value if key.ascending else -value) | |
return tuple(values) | |
print(sort_key([1, 2, 3, 4])) | |
# Output: (-3, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment