Python | List of tuples to String

• Last Updated : 29 Oct, 2019

Many times we can have a problem in which we need to perform interconversion between strings and in those cases, we can have a problem in which we need to convert a tuple list to raw, comma separated string. Let’s discuss certain ways in which this task can be performed.

Method #1 : Using str() + strip()
The combination of above functions can be used to solve this problem. In this, we just convert a list into string and strip the opening, closing square brackets of list to present a string.

 # Python3 code to demonstrate working of# List of tuples to String# using str() + strip()  # initialize listtest_list = [(1, 4), (5, 6), (8, 9), (3, 6)]  # printing original listprint("The original list is : " + str(test_list))  # List of tuples to String# using str() + strip()res = str(test_list).strip('[]')  # printing resultprint("Resultant string from list of tuple : " + res)
Output :
The original list is : [(1, 4), (5, 6), (8, 9), (3, 6)]
Resultant string from list of tuple : (1, 4), (5, 6), (8, 9), (3, 6)

Method #2 : Using map() + join()
This is yet another way in which this task can be performed. In this, we apply the string conversion function to each element and then join the tuples using join().

 # Python3 code to demonstrate working of# List of tuples to String# using map() + join()  # initialize listtest_list = [(1, 4), (5, 6), (8, 9), (3, 6)]  # printing original listprint("The original list is : " + str(test_list))  # List of tuples to String# using map() + join()res = ", ".join(map(str, test_list))  # printing resultprint("Resultant string from list of tuple : " + res)
Output :
The original list is : [(1, 4), (5, 6), (8, 9), (3, 6)]
Resultant string from list of tuple : (1, 4), (5, 6), (8, 9), (3, 6)

My Personal Notes arrow_drop_up