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 oriented solution.
Can you please help me to do it without collections?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…