Re: Insert item before each element of a list

2012-10-09 Thread mooremathewl
On Monday, October 8, 2012 10:06:50 PM UTC-4, Roy Smith wrote: In article mailman.1976.1349747963.27098.python-l...@python.org, (big snip) y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in range(len(x A statement ending in four close parens is usually

Insert item before each element of a list

2012-10-08 Thread mooremathewl
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]