I have a list of lists in python and I need to find how many times each sub-list has occurred. Here is a sample,
from collections import Counter list1 = [[ 1
Just convert the lists to tuple:
tuple
>>> c = Counter(tuple(x) for x in iter(list1)) >>> c Counter({(1.0, 2.66666667, 1.33333333): 3, (1.0, 4.0, 2.5): 2, (1.0, 2.0, 2.0): 1})
Remember to do the same for lookup:
>>> c[tuple(list1[0])] 2