How to count the occurrences of tuple and list inside a tuple with Python

1 Answer

0 votes
tpl = ('a', 'b', ('a', 'b'), [1, 2], ('a', 'b'), [1, 2], [1, 2])

count = tpl.count(('a', 'b'))
print(count)

count = tpl.count([1, 2])
print(count)



'''
run:

2
3

'''

 



answered Dec 10, 2019 by avibootz
...