I know some will frown on using numpy, but this is what I use most often.

You could build a dictionary using numpy. e.g.

- Code: Select all
`import numpy as np`

a = np.array(['a b c', 'a b c', 'a b c', 'e f g'])

counts = {}

while np.shape(a)!=0:

counts.update( {a[0]:np.size(a[a==a[0]],axis=0)} )

a = a[a!=a[0]]

This will give you a dictionary like: counts = {'a b c':3, 'e f g':1}

You could also continue using lists (likely more favorable to more users):

- Code: Select all
`# First make a unique list. `

# If we have same list as above:

a = ['a b c', 'a b c', 'a b c', 'e f g']

b = list( set( ['a b c', 'a b c', 'a b c', 'e f g'] ) )

counts = {}

for r in b:

counts.update( {r:a.count(r)} )

This should give the same dictionary as using numpy.