count occurrence of a list in a list of lists

Viewed 13123

Python

I have a list of lists. like

A = [[x,y],[a,b],[c,f],[e,f],[a,b],[x,y]]

I want to count how many times each list occurred in the main list.

My output should be like

[x,y] = 2
[a,b] = 2
[c,f] = 1 
[e,f] = 1
4 Answers

You can also use pandas for cleaner code:

pd.Series(A).explode().value_counts()
Related