How to count the items in a list until the first tuple in Python

1 Answer

0 votes
def count_items(lst_tpl): 
    counter = 0
    for n in lst_tpl: 
        if isinstance(n, tuple): 
            break
        counter = counter + 1
    return counter 
  
lst_tpl = [8, 9, 3, 0, 2, (5, 3, 1), 7, 4] 

print(count_items(lst_tpl)) 


'''
run:

5

'''

 



answered Dec 19, 2019 by avibootz

Related questions

1 answer 183 views
1 answer 202 views
2 answers 208 views
1 answer 185 views
1 answer 143 views
...