Sometimes, while working with data, we can have problem in which we need to convert the data list which in string format to list of tuples. This can occur in domains in which we have cross type inputs. Lets discuss certain ways in which this task can be performed.
Method #1 : Using loop +
The combination of above methods can be used to solve this task. In this we remake the string after processing for input to eval function to convert to Tuple lists.
The original string is : [(gfg, ), (is, ), (best, )] The list of Tuples is : [('gfg', ), ('is', ), ('best', )]
Method #2 : Using regex + list comprehension
The combination of above functionalities is used to perform this task. In this, we employ regex function to perform the task of resolving the String and list comprehension helps in reconstruction of record list.
The original string is : [(gfg, ), (is, ), (best, )] The list of Tuples is : [('gfg', ''), ('is', ''), ('best', '')]
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 | Convert string tuples to list tuples
- Python - Convert Uneven Lists into Records
- Python - Rear element extraction from list of tuples records
- Python - Records Maxima in List of Tuples
- Python | Convert list of tuples to dictionary value lists
- Python | Convert Lists to column tuples
- Python - Convert List of Lists to Tuple of Tuples
- Python | Remove duplicate tuples from list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Count tuples occurrence in list of tuples
- Python | Combining tuples in list of tuples
- Python | How to Concatenate tuples to nested tuples
- Python - Filter all uppercase characters Tuples from given list of tuples
- Python program to find Tuples with positive elements in List of tuples
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python - Nested Records List from Lists
- Python | Convert tuple records to single string
- Python - Convert Records List to Segregated 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 firstname.lastname@example.org. 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.