In this problem, we need to accept a list. The list can have nested tuples. We need to count the elements in a list until a tuple has been encountered.
Input : [4, 5, 6, 10, (1, 2, 3), 11, 2, 4] Output : 4 Input : [4, (5, 6), 10, (1, 2, 3), 11, 2, 4] Output : 1
In this program we will use the concept of isinstance() to verify whether we are encountering a tuple or not in our path of count. For detailed guide on isinstance() visit isinstance in Python.
- Python | Count occurrences of an element in a Tuple
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Sort a tuple by its float element
- Python | Convert a list into a tuple
- Python | Check if element is present in tuple of tuples
- Python | Convert a list into tuple of lists
- Python | Ways to iterate tuple list of lists
- Python | Count occurrences of an element in a list
- Python | Slicing list from Kth element to last element
- Python | Maximum sum of elements of list in a list of lists
- Python | tuple() Function
- Unpacking a Tuple in Python
- Python | Reversing a Tuple
- Python | How to get the last element of list
- Python | Program to convert a tuple to a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.