Python | Concatenate a list of tuples into a list by concatenating strings



Let`s try to understand this better with some code examples.

Method 1: Using list comprehension and join()

# Python code to convert a list of tuples to a list
# by concatenating the elements of the tuple

 
# Initialize the insertion list

Input = [( `Hello` , `There` ), ( ` Namastey` , `India` ), ( `Incredible` , ` India` )]

 
# using a connection and list comprehension

Output = [ `_` . join (temp) for temp in Input ]

 
# printout

print (Output)

Exit :

 [`Hello_There`,` Namastey_India`, `Incredible_India`] 

Method 2. Using map and join()

# Pyth on code to convert a list of tuples to a list
# by concatenating tuple elements

 
# Initialize the input list

Input = [( `Hello` , `There` ), ( ` Namastey` , `India` ), ( ` Incredible` , `India` )]

 
# use the map and join

Output = list ( map ( `_` . join , Input ))

 
# printout

print (Output)

Output:

 [`Hello_There`,` Namastey_India`, `Incredible_India`]