How to insert the contents of one list into another

list, python

Solution

You can do the following using the slice syntax on the left hand side of an assignment:

>>> array = ['the', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']
>>> array[1:1] = ['quick', 'brown']
>>> array
['the', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']

That's about as Pythonic as it gets!

Problem

I am trying to combine the contents of two lists, in order to later perform processing on the entire data set. I initially looked at the built in `insert` function, but it inserts as a list, rather than the contents of the list. I can slice and append the lists, but is there a cleaner / more Pythonic way of doing what I want than this: ``` array = ['the', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'] addition = ['quick', 'brown'] array = array[:1] + addition + array[1:] ```

Original source

Related problems