chauncey
9/11/2013 - 2:45 PM

Python Counter snippet

Python Counter snippet

In[1]: from collections import Counter

In[2]: ports = ['33680',
 '33680',
 '33680',
 '33677',
 '33677',
 '33677',
 '33677',
 '33677',
 '33677',
 '33677',
 '33677',
 '33677',
 '33860',
 '33860',
 '33860',
 '33860',
 '33860',
 '33656',
 '33656',
 '33656',
 '33656',
 '33656',
 '33656',
 '33656',
 '33656',
 '33656',
 '33656',
 '33656',
 '33157',
 '33157']
In [3]: Counter(ports)
Out[4]: Counter({'33656': 11, '33677': 9, '33860': 5, '33680': 3, '33157': 2})