This is probably quite a straightforward question, but I can't find an answer elsewhere so I'll ask. What is the best way to find the number of times an element appears in a nested list? For example:
my_list=[[a,b,c,d],[a,b,z,d],[a,c,f,e],[d,w,f,a]]
How would I find how many times 'a' is the first element of the list? Or more generally, how many times 'a' appears in my_list at all? I imagine there's a way to do this with collections.Counter, but I haven't been able to figure it out.
EDIT
For my_list, I would like an output of a:3
when counting if it's the first element of the list. If the question was changed to see if b
is the second element, the desired output would be b:2