0

I have a list with one list inside and I would like to count how many times is one element repeat. for example:

list = ['a','b','c',['a','d']]
find = 'a'
list.count(find)

The ouptput is 1, but I'm looking for 2.

There is any easy way to do it?

thanks

Alberto Aguilera
  • 311
  • 1
  • 5
  • 13

1 Answers1

0

Archive with chain.from_iterable

from itertools import chain
print(list(chain.from_iterable(lst)).count('a'))

First make your list flatten and get the count.

Vikas Periyadath
  • 3,088
  • 1
  • 21
  • 33