To concatenate two or more lists in python you can use ‘+’ operator, extend method or through iterator. Below are the few examples to concatenate lists.
Example 1: Using ‘+’ operator
list1 = [1,2,3]
list2 = [4,5,6]
#concatenating both the lists
final_list = list1 + list2
print(final_list)
Output:
[1,2,3,4,5,6]
Example 2: Using extend method
list1 = [1,2,3]
list2 = [4,5,6]
#concatenating using extend method
list1.extend(list2)
print(list1)
Output:
[1,2,3,4,5,6]
Example 3 :
list1 = [1,2,3]
list2 = [4,5,6]
#concatenating lists
list1 += list2
print(list1)
Output:
[1,2,3,4,5,6]
Each of the above examples has their own time complexity.
Also Read:
Shuffle List Python
Select Random Element from List : Python
Append element in list Python