Reputation: 63
How can I count how many times 3 appears in a list of list such as [[1,2,3,4],[2,3,4,5],[5,6,7,5]]
the output should be something like [1,1,0]
Upvotes: 1
Views: 137
Reputation: 5678
You can use the method list.count(element)
:
my_lists = [[1,2,3,4], [2,3,4,5], [5,6,7,5]]
[l.count(3) for l in my_lists]
>> [1, 1, 0]
Upvotes: 6