In python, if I have
A=[3,3,1,8,2,5,8,2,2]
and I do
set(A)
I get
{1, 2, 3, 5, 8}
i.e. a set with A's elements without duplicates
Is there a fast way to also have counters to know how many instances of every number I have in A?
Something like:
{[1, 1], [2, 3], [3, 2], [5, 1], [8, 2]}
Or do I have to implement it myself?
collections.Counter. Something like:result = collections.Counter(A). Then, you can iterate over it usingfor value, count in result.items():to obtain the value and counts respectively.