- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Flatten Tuples List to String in Python
When it is required to flatten a list of tuples into a string format, the 'str' method and the 'strip' method can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
A list of tuples basically contains tuples enclosed in a list. The 'strip' method will remove the specific character/value. The 'str' method will convert the given data type into a string data type.
Below is a demonstration of the same −
my_list = [(11, 14), (54, 56), (98, 0), (13, 76)] print("The list is : ") print(my_list) my_result = str(my_list).strip('') print("The list of tuple flattened to string is: ") print(my_result)
The list is : [(11, 14), (54, 56), (98, 0), (13, 76)] The list of tuple flattened to string is: (11, 14), (54, 56), (98, 0), (13, 76)
- A list of tuple is defined, and is displayed on the consol.
- The strip method is used to remove the '[' and ']' brackets.
- The above method is used after converting the given list of tuple to a string, which is done using the 'str' method.
- This is assigned to a value.
- It is displayed on the console.
- Flatten Nested List Iterator in Python
- Python program to Flatten Nested List to Tuple List
- Python - Ways to flatten a 2D list
- How to flatten a shallow list in Python?
- Flatten tuple of List to tuple in Python
- Flatten given list of dictionaries in Python
- Combining tuples in list of tuples in Python
- Count tuples occurrence in list of tuples in Python
- Convert list of tuples to list of list in Python
- Remove duplicate tuples from list of tuples in Python
- Python Program to Flatten a Nested List using Recursion
- Python Program to Flatten a List without using Recursion
- Convert list of tuples into list in Python
- Python program to find Tuples with positive elements in List of tuples
- Convert list of strings to list of tuples in Python