Counting occurrences without using collections.Counter
问题 I am trying to retrieve the most frequent and less frequent elements in a list. frequency([13,12,11,13,14,13,7,11,13,14,12,14,14]) My output is: ([7], [13, 14]) I tried it with: import collections s = [13,12,11,13,14,13,7,11,13,14,12,14,14] count = collections.Counter(s) mins = [a for a, b in count.items() if b == min(count.values())] maxes = [a for a, b in count.items() if b == max(count.values())] final_vals = [mins, maxes] But I don't want to use the collections module and try a more logic