Created
October 8, 2017 23:28
-
-
Save isaacd9/9bce61d9489d07c8de7762f32d5b976a 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
#!/usr/bin/env python3 | |
def tuple_sort(tuple_list): | |
tup_dict = {} | |
first_sorted = list(sorted(tuple_list, key=lambda tup: tup[0], reverse=True)) | |
second_sorted = list(sorted(tuple_list, key=lambda tup: tup[1], reverse=True)) | |
for index, tup in enumerate(first_sorted): | |
tup_dict[tup] = index | |
for index, tup in enumerate(second_sorted): | |
if index < tup_dict[tup]: | |
tup_dict[tup] = index | |
for index, tup in enumerate(tuple_list): | |
tuple_list[index] = tup_dict[tup] | |
return tuple_list | |
def test(): | |
points = [(1,0)] | |
solution = [0] | |
print(tuple_sort(points), solution) | |
points = [(1, 1,), (1, 2), (3, 3)] | |
solution = [1, 1, 0] | |
print(tuple_sort(points), solution) | |
points = [(1, 4), (7, 7), (8, 1), (4,5)] | |
solution = [2, 0, 0, 1] | |
print(tuple_sort(points), solution) | |
if __name__ == '__main__': | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment