How to concatenate two lists in Python?
In Python, we can use +
operator to concatenate two or multiple lists.
Python Source Code: Concatenation of Two Lists
list_1 = [1, 2, 3, 4]
list_2 = ["one", "two", "three"]
concatenated_list = list_1 + list_2
print("Concatenated list is: ", concatenated_list)
Output
Concatenated list is: [1, 2, 3, 4, 'one', 'two', 'three']
Alternatively, in Python >= 3.5, we can use unpacking of lists within list literals to concatenate any iterables. See example below:
list_1 = [1, 2, 3, 4]
list_2 = ["one", "two", "three"]
concatenated_list = [*list_1, *list_2]
print("Concatenated list is: ", concatenated_list)
Output
Concatenated list is: [1, 2, 3, 4, 'one', 'two', 'three']