w3resource logo
Python Exercises

Python Exercise: Count the elements in a list until an element is a tuple

Python tuple: Exercise-24 with Solution

Write a Python program to count the elements in a list until an element is a tuple.

Sample Solution:-

Python Code:

num = [10,20,30,(10,20),40]
ctr = 0
for n in num:
    if isinstance(n, tuple):
        break
    ctr += 1
print(ctr)

Sample Output:

3 

Python Code Editor:

num = [10,20,30,(10,20),40]
ctr = 0
for n in num:
    if isinstance(n, tuple):
        break
    ctr += 1
print(ctr)

Improve this sample solution and post your code through Disqus