- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 −
Example
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)
Output
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)
Explanation
- 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.
- Related Articles
- Python program to Flatten Nested List to Tuple List
- Flatten Nested List Iterator in Python
- How to flatten a shallow list in Python?
- Flatten tuple of List to tuple in Python
- Python - Ways to flatten a 2D list
- Flatten given list of dictionaries in Python
- Combining tuples in list of tuples in Python
- Convert list of tuples to list of list in Python
- Count tuples occurrence in list of tuples in Python
- Python Program to Flatten a Nested List using Recursion
- Python Program to Flatten a List without using Recursion
- Remove duplicate tuples from list of tuples in Python
- Python program to find Tuples with positive elements in List of tuples
- Convert list of strings to list of tuples in Python
- Convert list of tuples to list of strings in Python

Advertisements