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)