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)

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.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program