⊗pyPmLsLCE 47 of 208 menu

Combining Lists with the extend Method in Python

If we need to combine two lists into one, we can use the extend method. In this case, the second list will be added to the end of the first:

lst1 = [1, 2, 3] lst2 = [4, 5, 6] lst1.extend(lst2) print(lst1) # [1, 2, 3, 4, 5, 6]

Two lists are given:

lst1 = ['a', 'b', 'c'] lst2 = ['d', 'e']

Combine these lists into one.

The lists are given:

lst1 = ['a', 'b', 'c'] lst2 = ['d', 'e'] lst3 = [1, 2, 3]

First add the third list to the first one. Then combine the result with lst2.

byenru