How to count an item in all sublists of a list in Python

1 Answer

0 votes
def count_sublists_item(lst, ch): 
    return sum(ch in item for item in lst) 

lst = (['x', 'y'], ['b', 'y', 'w'], ['p', 'o', 's', 'm'], ['y'])  
ch = 'y'
print(count_sublists_item(lst, ch))



'''
run:

3

'''

 



answered Dec 26, 2019 by avibootz
...