Pythonically inserting multiple values to a list
idioms, insert, list, python
Solution
I might do something like this:
>>> a = ["Three","Four","Five","Six"]
>>> b = range(3,7)
>>> zip(a,b)
[('Three', 3), ('Four', 4), ('Five', 5), ('Six', 6)]
>>> [term for pair in zip(a,b) for term in pair]
['Three', 3, 'Four', 4, 'Five', 5, 'Six', 6]
or, using `itertools.chain`:
>>> from itertools import chain
>>> list(chain.from_iterable(zip(a,b)))
['Three', 3, 'Four', 4, 'Five', 5, 'Six', 6]
Problem
I want to turn this list: ``` l=["Three","Four","Five","Six"] ``` into this one: ``` ['Three', 3, 'Four', 4, 'Five', 5, 'Six', 6] ``` and I used this code (which works well) to do it: ``` for i,j in zip(range(1,len(l)*2,2),range(3,7)*2): l.insert(i,j) ``` But I guess Python would not be proud of it. Is there a shorter way for this?