While working with Python lists, due to its heterogenous nature, we can have a problem in which we need to convert data type of each nested element of list to particular type. In mixed list, this becomes complex. Let’s discuss certain way in which this task can be performed.
Input : test_list = [(‘7’, [‘8’, (‘5’, )])]
Output : [(7, [8, (5, )])]
Input : test_list = [‘6’]
Output : 
Method : Using recursion +
The combination of above functions can be used to solve this problem. In this, we use isinstance() to get the data type of element of list, and if its container, the inner elements are recursed to perform conversion.
The original list is : ['6', '89', ('7', ['8', '10']), ['11', '15']] Data after type conversion : [6, 89, (7, [8, 10]), [11, 15]]
- Python - Extract Even elements in Nested Mixed Tuple
- Python - Elements Frequency in Mixed Nested Tuple
- Python | Convert mixed data types tuple list to string list
- Python | Check if a nested list is a subset of another nested list
- Sort mixed list in Python
- Python | Integer count in Mixed List
- Python | Count String occurrences in mixed list
- Python | Lexicographically smallest string in mixed list
- Python | Find Mixed Combinations of string and list
- Type Conversion in Python
- Python - Maximum column values in mixed length 2D List
- Python | Convert numeric String to integers in mixed List
- Python | Multiply Integer in Mixed List of string and numbers
- Python - Numeric Sort in Mixed Pair String List
- Python - Convert delimiter seperated Mixed String to valid List
- Python | Type conversion of dictionary items
- Python | Type conversion in dictionary values
- Python | Convert string List to Nested Character List
- Python | Find maximum length sub-list in a nested list
- Python | Pair and combine nested list to tuple list
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.