Received: by 10.180.91.231 with SMTP id ch7mr3177263wib.1.1350352536691; Mon, 15 Oct 2012 18:55:36 -0700 (PDT) Path: q10ni65138167wif.0!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.139.MISMATCH!xlned.com!feeder7.xlned.com!multikabel.net!newsfeed10.multikabel.net!feed.xsnews.nl!border-1.ams.xsnews.nl!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-l...@python.org Delivered-To: python-l...@mail.python.org X-Spam-Status: OK 0.050 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '[1,': 0.09; 'feedback.': 0.15; 'slightly': 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'itertools': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'subject:item': 0.16; 'wrote:': 0.17; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'this?': 0.28; 'subject:list': 0.28; '>>>>': 0.29; 'received:192.168.1.3': 0.29; 'skip:l 40': 0.33; 'to:addr:python-list': 0.33; 'there': 0.35; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'email addr:gmail.com': 0.63; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'gut': 0.84; 'reply-to:addr:python.org': 0.84; 'subject:before': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=OqzNOlDt c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=AAvI7MrX_rgA:10 a=JN4pC4BO-gIA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=TOiHKIfACYEA:10 a=pGLkceISAAAA:8 a=7InFscZ-cJ2aJhpcO9QA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Mon, 08 Oct 2012 20:43:12 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: python-l...@python.org Subject: Re: Insert item before each element of a list References: In-Reply-To: X-BeenThere: python-l...@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-l...@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349725395 news.xs4all.nl 6908 [2001:888:2000:d::a6]:39806 X-Complaints-To: ab...@xs4all.nl Bytes: 3463 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 2012-10-08 20:28, mooremath...@gmail.com 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] > > I appreciate any and all feedback. > Slightly better is: y = list(itertools.chain.from_iterable(('insertme', i) for i in x))