I have a list of lists in python:
x=[['1', '1', '2', '2', '2', '2', '1', '0', '0'],
['1', '1', '1', '0', '0', '1', '1', '0', '0'],
['0', '0', '1', '2', '1', '0', '2', '1', '1']]
I want to know how count the occurrences in the list of lists
My output should be like (without using numpy and Counter):
{'1': 3, '2': 4, '0': 2}
{'1': 5, '0': 4}
{'0': 3, '1': 4, '2': 2}
Now, I have the solution which works for only one list, but doesn't work for list of lists.
newlist=[]
for el in x:
n=el[0]
newlist.append(n)
print(newlist)
list2=dict((i, newlist.count(i)) for i in newlist)
print(list2)
I did't find an answer on another thread. Is anyone able to help? :)