How to put elements of a list in another list

Asked

Viewed 3,476 times

4

I have the following code:

a = list()
b = list()
c = list()

a = (1,2,3)
b = (2,4,6)

c = a + b[1]

print(c)

How do I add an element from a list to another list?

1 answer

3


Use the method extend to add list items a and the append to add the second item in the list b:

a = [1, 2, 3]
b = [2, 4, 6]
c = []

c.extend(a)
c.append(b[1])

print(c)

# [1, 2, 3, 4]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.