Lists are not hashed, but you can use tuples as workarounds:
l = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['a', 'b', 'c'], ['c', 'b', 'a'] ] new_l = list(map(tuple, l)) final_l = {a:new_l.count(a) for a in new_l}
Output:
{('a', 'b', 'c'): 2, ('d', 'e', 'f'): 1, ('c', 'b', 'a'): 1}
Or, if you really want to use lists, you can create your own class that mimics the functionality of dictionary hash lists:
class List_Count: def __init__(self, data): new_data = list(map(tuple, data)) self.__data = {i:new_data.count(i) for i in new_data} def __getitem__(self, val): newval = [b for a, b in self.__data.items() if list(a) == val] if not newval: raise KeyError("{} not found".format(val)) return newval[0] def __repr__(self): return "{"+"{}".format(', '.join("{}:{}".format(list(a), b) for a, b in self.__data.items()))+"}" l = List_Count([ ['a', 'b', 'c'], ['d', 'e', 'f'], ['a', 'b', 'c'], ['c', 'b', 'a'] ]) print(l) print(l[['a', 'b', 'c']])
Output:
{['a', 'b', 'c']:2, ['d', 'e', 'f']:1, ['c', 'b', 'a']:1} 2