merge two lists alternatively python code example
Example 1: merge two lists
# Makes list1 longer by appending the elements of list2 at the end.
list1.extend(list2)
Example 2: merge two lists python
>>> l1 = [1, 2, 3]
>>> l2 = [4, 5, 6]
>>> joined_list = [*l1, *l2] # unpack both iterables in a list literal
>>> print(joined_list)
[1, 2, 3, 4, 5, 6]