Sometimes, while working with records, we can have a problem in which an element of a record is another tuple records and we might have to remove the nested records. This is a problem which does not occur commonly, but having a solution to it is useful. Let’s discuss certain way in which this task can be performed.
Method : Using loop +
isintance() + enumerate()
This problem can be solved using the above functionalities. In this, we just loop through the elements using
enumerate() to get the index count of it and check the type using
isinstance() and recreate the new tuple by checking ignoring tuple records.
The original tuple : (1, 5, 7, (4, 6), 10) Elements after removal of nested records : (1, 5, 7, 10)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python - Remove None Nested Records
- Python - Remove all duplicate occurring tuple records
- Python | Nested Records Modulo
- Python - Nested Records List from Lists
- Python - Test for empty Nested Records
- Python | Convert tuple records to single string
- Python | Intersection in Tuple Records Data
- Python | Minimum K records of Nth index in tuple list
- Python - Find minimum k records from tuple list
- Python - Prefix tuple records
- Python | Check if a nested list is a subset of another nested list
- Python - Remove K from Records
- Python - Remove Consecutive K element records
- Python - Remove records if Key not present
- Python | Pair and combine nested list to tuple list
- Python | How to get unique elements in nested tuple
- Python | Cummulative Nested Tuple Column Product
- Python - Elements Frequency in Mixed Nested Tuple
- Python - Nested List to single value Tuple
- Python - Convert Nested Tuple to Custom Key Dictionary
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.