Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'iterate': 0.09; 'cc:addr :python-list': 0.10; 'assume': 0.11; 'itertools': 0.16; 'wrote:': 0.17; 'items.': 0.17; 'email addr:gmail.com>': 0.20; 'import': 0.21; 'thanks.': 0.21; "i'd": 0.22; 'cc:2**0': 0.23; '>': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'wondering': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'chris': 0.28; 'run': 0.28; 'restart': 0.29; 'sensible': 0.29; 'points': 0.29; 'skip:& 10': 0.29; 'received:74.125.82': 0.33; 'point.': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'whatever': 0.35; 'there': 0.35; 'received:74.125': 0.36; 'be.': 0.36; 'late': 0.37; 'subject:: ': 0.38; 'more': 0.63; 'due': 0.66; '2013': 0.84; 'subject:over': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=7v3OAu9H8/kT/9EiPNGrJVzkyhT117IhZk/41sZ1wEo=; b=NoDpZYpLVUtqh9aI1mUPyf4YywCPSQtNNwmNhiMqAiniNSAFoDjFqSsFLcJVv9LqYS byBmhYKMi1BGBB8HjGtc2Tv0eardirDNV8QsjzLCKtuHLd05g2hFrPXyU3DiDyAyGQEF aC3fvrkM06+q47m849Tir/S0KV6M9zz4DMco+ZPM+Ws0lGisbnnxRqU7usqWT4pTB64X 8x5Yq0bz/jviklYbV1y4we4DfqNg/1SZpWAca5YDoRVvEhxwzfpnM1zuWIOpovn9dNAB BA6qzcsNhcqnmLNSl8WV4bIUaRbBmrtN65EYYuCn0BBZZS3jUh5tRkycQFWBRIRvp5kd zWOA== MIME-Version: 1.0 X-Received: by 10.180.101.41 with SMTP id fd9mr26638456wib.20.1362648886665; Thu, 07 Mar 2013 01:34:46 -0800 (PST) In-Reply-To: References: Date: Thu, 7 Mar 2013 09:34:46 +0000 Subject: Re: iterating over a list as if it were a circular list From: Sven To: Chris Rebert Content-Type: multipart/alternative; boundary=f46d041826c2d7eb8c04d7526a61 Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362648888 news.xs4all.nl 6986 [2001:888:2000:d::a6]:36466 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40734 --f46d041826c2d7eb8c04d7526a61 Content-Type: text/plain; charset=ISO-8859-1 On 7 March 2013 09:31, Chris Rebert wrote: > On Mar 7, 2013 1:24 AM, "Sven" wrote: > > > > I was wondering what the best approach for the following might be. > > > > Say you have a list P of points and another list N of other items. You > can always assume that > > > > len(N) <= len(P) > > > > Now I would like to iterate over P and place one N at each point. > However if you run out of N I'd like to restart from N[0] and carry on > until all the points have been populated. > > Untested due to the late hour: > > import itertools > > for p, n in itertools.izip(P, itertools.cycle(N)): > # do whatever > I knew there was a more sensible way to do it. Thanks. -- ./Sven --f46d041826c2d7eb8c04d7526a61 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 7 March 2013 09:31, Chris Rebert <= clp2@rebertia.com> wrote:

On Mar 7, 2013 1:24 AM, "Sven" &= lt;svenito@gmail.com= > wrote:
>
> I was wondering what the best approach for the following might be.
>
> Say you have a list P of points and another list N of other items. You= can always assume that
>
> len(N) <=3D len(P)
>
> Now I would like to iterate over P and place one N at each point. Howe= ver if you run out of N I'd like to restart from N[0] and carry on unti= l all the points have been populated.

Untested due to the late hour:

import itertools

for p, n in itertools.izip(P, itertools.cycle(N)):
=A0=A0=A0 # do whatever


I knew there was a = more sensible way to do it. Thanks.




--
.= /Sven
--f46d041826c2d7eb8c04d7526a61--