Merge Two Lists in Python:
a = [1, 2, 3]
b = [4, 5, 6]
# Merge the two lists and assign
# the result to a new list
c = a + b
print(c)
a = [1, 2, 3]
b = [4, 5, 6]
# Add all elements from list 'b' to the end of list 'a'
a.extend(b)
print(a)
Using the * Operator
We can use the *** operator** to unpack the elements of multiple lists and combine them into a new list.
a = [1, 2, 3]
b = [4, 5, 6]
# Use the unpacking operator to merge the lists
c = [*a, *b]
print(c)
Using for loop
We can also merge two lists using a simple for loop. This approach is provides more control if we need to perform additional operations on the elements while merging.
a = [1, 2, 3]
b = [4, 5, 6]
# Initialize an empty list to store the merged elements
res = []
# Append all elements from the first list
for val in a:
res.append(val)
# Append all elements from the second list
for val in b:
res.append(val)
print(res)
https://www.geeksforgeeks.org/python-ways-to-concatenate-two-lists/