How do I concatenate two lists in Python?
Example:
listone = [1, 2, 3]
listtwo = [4, 5, 6]
Expected outcome:
>&g
a=[1,2,3]
b=[4,5,6]
c=a+b
print(c)
OUTPUT:
>>> [1, 2, 3, 4, 5, 6]
In the above code "+" operator is used to concatenate the 2 lists into a single list.
ANOTHER SOLUTION:
a=[1,2,3]
b=[4,5,6]
c=[] #Empty list in which we are going to append the values of list (a) and (b)
for i in a:
c.append(i)
for j in b:
c.append(j)
print(c)
OUTPUT:
>>> [1, 2, 3, 4, 5, 6]