I am working on a cdr visualization and I need to get the number of each countries. I sorted the countries but I couldnt get the numbers.

def country(data):
N = []

for i in data:
      N.append(i.getcallee_country())

counts = [(i, len(list(c))) for i,c in groupby(N)]     
print(counts)

1 Answers

1
Lesiak On Best Solutions

Counter looks like a perfect match for the problem

import collections

print collections.Counter(['a', 'b', 'c', 'a', 'b', 'b'])

Alternatively:

c = Counter()
for value in your_list:
    c[value] += 1