I have an array and I want to count the occurrence of each item in the array.
I have managed to use a map function to produce a list of tuples.
def
You could use Counter
:
from collections import Counter
arr = [11817685, 2014036792, 2014047115, 11817685]
counter = Counter(arr)
print zip(counter.keys(), counter.values())
EDIT:
As pointed by @ShadowRanger Counter
has items()
method:
from collections import Counter
arr = [11817685, 2014036792, 2014047115, 11817685]
print Counter(arr).items()