Skip to content

Instantly share code, notes, and snippets.

@isaacd9
Created October 8, 2017 23:28
Show Gist options
  • Save isaacd9/9bce61d9489d07c8de7762f32d5b976a to your computer and use it in GitHub Desktop.
Save isaacd9/9bce61d9489d07c8de7762f32d5b976a to your computer and use it in GitHub Desktop.
#!/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