I'm trying to count the frequency of occurrence of the first element of a list within a list.
the list is:
list = [[4, 2, 1, 3], [4, 3, 1, 2], [4, 3, 1, 2], [1, 3, 4, 2], [2, 3, 4, 1], [2, 1, 3, 4]]
I want to count the first element of each list within the entire list and print to screen the number that appears the most frequent. Which in this example would be 4.
Any suggestions on how to do this?
If I create a counter to count frequencies using:
Counter(l[0] for l in firstValue).most_common())
If there was 2 or more numbers with the highest frequency of occurrences how would I select the smallest number?
E.g
counter = [(4, 3), (3, 3), (2, 2), (1, 1)]
How would I be able to sort this to print the smallest number that has the greatest frequency of occurrence. (e.g 3 in this example)