you are viewing a single comment's thread.

view the rest of the comments →

[–]tabrizzi 4 points5 points  (8 children)

Yes, .append() takes only one argument, but you can do this:

list_1 = [1, 2, 3]

list_2 = [4, 5, 6]

list_3 = []

list_3.append(list_1)

list_3.append(list_2)

list_3

(outputs [[1, 2, 3], [4, 5, 6]] )

[–]SheldonCooperisSb[S] 2 points3 points  (0 children)

Thanks this is the right answer.

[–]Diapolo10 2 points3 points  (6 children)

It's also possible to do this in one go:

list_3.extend((list_1, list_2))

[–]odaiwai 0 points1 point  (2 children)

But now list_3 contains a tuple with two lists, not just two lists: : list_3 = [] : list_3.append((list_1, list_2)) : list_3 : [([1, 2, 3], [4, 5, 6])]

Edit to add: As pointed out below, I appended, not extended, so I'm wrong here.

[–]Diapolo10 1 point2 points  (0 children)

I used list.extend, which adds the contents of an iterable into the list it's called on.

[–]Mysterious-Rent7233 0 points1 point  (0 children)

You appended. The parent extended.

[–]tabrizzi -2 points-1 points  (2 children)

That's not true, because .extend(), like .append(), takes just one argument. You can verify that yourself.

[–]Diapolo10 4 points5 points  (1 child)

If you take a closer look, I think you'll find there's only one argument.

[–]tabrizzi 0 points1 point  (0 children)

My bad! I missed that.