Skip to content

Instantly share code, notes, and snippets.

@Myestery
Last active November 2, 2022 08:56
Show Gist options
  • Save Myestery/58f37c62a39544a93a66629b3dc2e4b4 to your computer and use it in GitHub Desktop.
Save Myestery/58f37c62a39544a93a66629b3dc2e4b4 to your computer and use it in GitHub Desktop.
Get nth most rate signature
def nth_most_rate_signature(list,n):
# save all enteries to a map
# key is the signature
# value is the number of times it appears
map = {}
for i in list:
if i in map:
map[i] += 1
else:
map[i] = 1
# print(map)
sorted_list = sorted(map.items(), key=lambda x: x[1])
if n > len(sorted_list):
return None
# print(sorted_list)
return sorted_list[n-1][0]
print(nth_most_rate_signature([5,4,5,4,5,4,4,5,3,3,3,2,2,1,5],2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment