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 occurrence of all elements of list in a tuple
- Python | Count occurrences of an element in a Tuple
- Python | Join tuple elements in a list
- Python | Replace elements in second list with index of same element in first list
- Python | Count the sublists containing given element in a list
- Python | Count occurrences of an element in a list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Merge list of tuple into list by joining the strings
- Python | Pair and combine nested list to tuple list
- Python | Find all elements count in list
- 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 | Sort tuple based on occurrence of first element
- Python | Dictionary to list of tuple conversion
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.