Message from discussion
Insert item before each element of a list
Received: by 10.180.86.97 with SMTP id o1mr3124958wiz.2.1350352582817;
Mon, 15 Oct 2012 18:56:22 -0700 (PDT)
Path: q10ni65138160wif.0!nntp.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!216.196.110.144.MISMATCH!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news.mixmin.net!news2.arglkargh.de!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path: <ian.g.ke...@gmail.com>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@mail.python.org
X-Spam-Status: OK 0.016
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'variant': 0.07; 'len(x)':
0.09; 'restriction': 0.09; "wouldn't": 0.11; 'iterables': 0.16;
'oct': 0.16; 'subject:item': 0.16; 'truncates': 0.16; 'mon,':
0.16; 'wrote:': 0.17; 'either.': 0.22; 'runs': 0.22; 'header:In-
Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27;
'subject:list': 0.28; 'far.': 0.29; 'points': 0.29; 'probably':
0.29; 'compatible': 0.30; 'to:addr:python-list': 0.33;
'received:google.com': 0.34; 'pm,': 0.35; 'too.': 0.35;
'received:209.85': 0.35; 'but': 0.36; 'method': 0.36; 'possible':
0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38;
'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'remove':
0.61; 'subject:before': 0.84; 'to:name:python': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
h=mime-version:in-reply-to:references:from:date:message-id:subject:to
:content-type; bh=NP/UmPxPKj10He0JdLLWThoSQnRJVlQqIhvo0ZpKkTA=;
b=x5/gHBGbWToGPQ110nzjSf0ZO9s+37bDv+6rR3sjCS/OMc84GmhIpY4+06w3KoOnwz
bHtelGZ2CAW7ex/mGYaR9HeVzJLEI4v9ghHLGImGu/NROZ47RprS3CqYCjfWuWwNALGe
z/By8TIhBDPrLCGjSWIMcb2RH5pWBIZU5XoR2tHZvgm3z+e9AV+OTaG3W4Zt/hSA0LmB
z/+0UJzXPUUbtskeDs4rI8lZr2iAzNPdYF8IeG/QZSWqM/9ga3HkIIoblOYJgNw4XyFB
LdAmbxMNbkQ8DwOWEb1vdG9wYQdrhntj4qSIkr3ofqlpJxbeEn3CAMeldt4rx/sfCK/F
prww==
MIME-Version: 1.0
In-Reply-To: <CAN1F8qXxCp6iNjdMYjwsDt_u6JET5rkYpVryAzSRPDeCThZyGQ@mail.gmail.com>
References: <fc55bb2e-fdc0-405c-89b5-290aa4fc6c63@googlegroups.com>
<CAN1F8qXxCp6iNjdMYjwsDt_u6JET5rkYpVryAzSRPDeCThZ...@mail.gmail.com>
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Mon, 8 Oct 2012 14:04:38 -0600
Subject: Re: Insert item before each element of a list
To: Python <python-l...@python.org>
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/options/python-list>,
<mailto:python-list-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.1965.1349726710.27098.python-l...@python.org>
Lines: 11
NNTP-Posting-Host: 2001:888:2000:d::a6
X-Trace: 1349726710 news.xs4all.nl 6909 [2001:888:2000:d::a6]:57336
X-Complaints-To: ab...@xs4all.nl
Bytes: 3673
Content-Type: text/plain; charset=ISO-8859-1
On Mon, Oct 8, 2012 at 1:52 PM, Joshua Landau
<joshua.landau...@gmail.com> wrote:
> But it's not far. I wouldn't use Ian Kelly's method (no offence), because of
> len(x): it's less compatible with iterables. Others have ninja'd me with
> good comments, too.
That's fair, I probably wouldn't use it either. It points to a
possible need for a roundrobin variant that truncates like zip when
one of the iterables runs out. It would have to do some look-ahead,
but it would remove the need for the len(x) restriction on
itertools.repeat.