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 182 views
1 answer 201 views
2 answers 207 views
1 answer 184 views
1 answer 142 views
...