Compuser7 - 1 year ago 72

Python Question

Given two lists:

`x = [1,2,3]`

y = [4,5,6]

What is the syntax to:

- Insert into
`x`

such that`y`

now looks like`y`

?`[1, 2, 3, [4, 5, 6]]`

- Insert all the items of into
`x`

such that`y`

now looks like`y`

?`[1, 2, 3, 4, 5, 6]`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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]
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**