I'm new to programming and I find myself in some trouble. I have a list, and I want to know how many times an item shows up and then print the minimum value that shows up. So if I have A=[1e, 2b, 3u, 2b, 1e, 1e, 3u, 3u]
, I want to show something like "What you want is a 2"
, where 2 is the least amount of times something shows up, in this case 2b
is the one that shows up the least amount of times. This is my code so far:
import collections
collections.Counter(A)
B = {key: value for (key, value) in A}
result = []
min_value = None
minimum = min(B, key=B.get)
print(minimum, B[minimum])
The output for this is 2b
, but what I want the amount of times 2b shows up, since it is the one that shows up the least. I'm having some difficulty with this.
To clarify, I want the minimum number in a counter result.
Any help would be appreciated, I'm sorry if my question is confusing English is not my first language and it's my first time doing something like this.