Sometimes we come across this type of problem in which we require to leave each element of one list with the other. This type of problems usually occurs in developments in which we have the combined information, like names and surnames in different lists. Let’s discuss certain ways in which this task can be performed.
Method #1 : Using list comprehension + zip()
List comprehension does the task of concatenating the similar index elements. The task of zip function is concatenating the resultant string into a single list and return list.
# Python3 code to demonstrate # interlist element concatenation # using list comprehension + zip() # initializing lists test_list1 = ["Geeksfor", "i", "be"] test_list2 = ['Geeks', 's', 'st'] # printing original lists print ("The original list 1 is : " + str(test_list1)) print ("The original list 2 is : " + str(test_list2)) # using list comprehension + zip() # interlist element concatenation res = [i + j for i, j in zip(test_list1, test_list2)] # printing result print ("The list after element concatenation is : " + str(res)) |
The original list 1 is : ['Geeksfor', 'i', 'be'] The original list 2 is : ['Geeks', 's', 'st'] The list after element concatenation is : ['GeeksforGeeks', 'is', 'best']
Method #2 : Using map() + lambda + zip()
The task of mapping each index element with each other is performed by map function in this method and the functionality of addition is performed by lambda function. This method works only in Python2.
# Python code to demonstrate # interlist element concatenation # using map() + lambda + zip() # initializing lists test_list1 = ["Geeksfor", "i", "be"] test_list2 = ['Geeks', 's', 'st'] # printing original lists print ("The original list 1 is : " + str(test_list1)) print ("The original list 2 is : " + str(test_list2)) # using map() + lambda + zip() # interlist element concatenation res = list(map(lambda(i, j): i + j, zip(test_list1, test_list2))) # printing result print ("The list after element concatenation is : " + str(res)) |
The original list 1 is : ['Geeksfor', 'i', 'be'] The original list 2 is : ['Geeks', 's', 'st'] The list after element concatenation is : ['GeeksforGeeks', 'is', 'best']
Recommended Posts:
- Python | Elementwise AND in tuples
- Python | Ways to concatenate two lists
- Python | Concatenate dictionary value lists
- Python program to concatenate every elements across lists
- Python program to concatenate two Integer values into one
- Concatenate two strings using Operator Overloading in Python
- Python | Zipping two lists of lists
- Concatenate two columns of Pandas dataframe
- How to Concatenate two 2-dimensional NumPy Arrays?
- Python | Pandas Series.str.cat() to concatenate string
- Python | Merge, Join and Concatenate DataFrames using Panda
- Python program to concatenate Strings around K
- Python | Ways to concatenate boolean to string
- Python | Ways to concatenate tuples
- Python | Numpy np.ma.concatenate() method
- Python | How to Concatenate tuples to nested tuples
- Python | Concatenate N consecutive elements in String list
- Python - Concatenate Kth element in Tuple List
- Python - Concatenate consecutive elements in Tuple
- Python | Concatenate All Records
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

