[email protected] wrote:
> What's the best way to accomplish this? Am I over-complicating it? My
> gut feeling is there is a better way than the following:
>
>>>> import itertools
>>>> x = [1, 2, 3]
>>>> y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
>>>> range(len(x)))) y
> ['insertme', 1, 'insertme', 2, 'insertme', 3]
Less general than chain.from_iterable(izip(repeat("insertme"), x)):
>>> x = [1, 2, 3]
>>> y = 2*len(x)*["insertme"]
>>> y[1::2] = x
>>> y
['insertme', 1, 'insertme', 2, 'insertme', 3]
--
http://mail.python.org/mailman/listinfo/python-list