user1813564
user1813564

Reputation: 63

How to count number in separate list in a list for python?

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

Answers (1)

Nicolas
Nicolas

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

Related Questions