If I have
animal = [['cat', 'cat', 'dog'], ['cat', 'cat', 'dog'], ['cat', 'cat', 'dog']]
and
item_to_find = ['cat', 'dog']
how do I calculate the number of times each string inside item_to_find
can be found in animal
? for example, for 'cat'
, the answer would be 6, and for 'dog'
it would be 3. I need to do this without using collectiouns.Counter
or a dictionary. I tried to use count
, but it only works if it's a list of strings, and not a list of list of strings.
I tried to do it this way:
for i in item_to_find:
print(animal.count(i))
but like I was saying this only works for a list of strings and not a list of list of strings.
My result would look like something like this: [6, 3]
(as a list).