I have a piece of code here that is supposed to return the least common element in a list of elements, ordered by commonality:
def getSingle(arr):
from collections import Counter
c = Counter(arr)
return c.most_common()[-1] # return the least common one -> (key,amounts) tuple
arr1 = [5, 3, 4, 3, 5, 5, 3]
counter = getSingle(arr1)
print (counter[0])
My question is in the significance of the -1 in return c.most_common()[-1]
. Changing this value to any other breaks the code as the least common element is no longer returned. So, what does the -1 mean in this context?