Placing elements from a list in another list

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?

    
asked by anonymous 17.08.2016 / 04:57

1 answer

3

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

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

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

print(c)

# [1, 2, 3, 4]
    
17.08.2016 / 05:22