What is the syntax to insert one list into another list in python?

append, extend, list, python

Solution

Do you mean `append`?

>>> x = [1,2,3]
>>> y = [4,5,6]
>>> x.append(y)
>>> x
[1, 2, 3, [4, 5, 6]]

Or merge?

>>> x = [1,2,3]
>>> y = [4,5,6]
>>> x + y
[1, 2, 3, 4, 5, 6]
>>> x.extend(y)
>>> x
[1, 2, 3, 4, 5, 6] 

Problem

Given two lists: ``` x = [1,2,3] y = [4,5,6] ``` What is the syntax to: - Insert `x` into `y` such that `y` now looks like `[1, 2, 3, [4, 5, 6]]`? - Insert all the items of `x` into `y` such that `y` now looks like `[1, 2, 3, 4, 5, 6]`?

Original source

Related problems