Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40728

Re: iterating over a list as if it were a circular list

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.065
X-Spam-Evidence '*H*': 0.87; '*S*': 0.00; 'iterate': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; 'thu,': 0.17; "i'd": 0.22; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'run': 0.28; 'restart': 0.29; 'points': 0.29; 'to:addr:python- list': 0.33; 'point.': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; '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:content-type; bh=fPBsT2A1sjrAfnMXdOfs5BlxTBCrjFfT4NQgILJOBS8=; b=AfoBnCW6rDLGIdJXqphiTVHIVrQqLqeMvEDOsXGQwjevzQJ92maAk9+OrS2ULDXzae Rz3eBLe/iwo+T3kAbx4R4nwFjlXexMYORdvq2VD02zjwxGS1NQQStRLGUlE/Mar3l/il AATaTy7YP8D0KxcSKqVtxkvcRgg2IGPFs4eIrpYw98k3GBSMh7XkRqUc931VhTUYJxv1 8fnQOrQRrrcTyqQPsSr51Y9wxkjOwSvDqKLOgchiyZoCsyMxOfKr/DDCrLfhmpDj7oBh TvB8FOYEa8Y/8LoRH5PfxLQqZVYahyk6EVs6eELFJxk9LfH+WtH+s8Do5r11t1qDgJEU gK0g==
MIME-Version 1.0
X-Received by 10.52.88.197 with SMTP id bi5mr10994254vdb.58.1362648482993; Thu, 07 Mar 2013 01:28:02 -0800 (PST)
In-Reply-To <CAEH=cXWXwOf6QnNur4V3HNBZ2i13gVnOiJDOOyCZs1Putc_mug@mail.gmail.com>
References <CAEH=cXWXwOf6QnNur4V3HNBZ2i13gVnOiJDOOyCZs1Putc_mug@mail.gmail.com>
Date Thu, 7 Mar 2013 20:28:02 +1100
Subject Re: iterating over a list as if it were a circular list
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@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-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2995.1362648484.2939.python-list@python.org> (permalink)
Lines 8
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362648484 news.xs4all.nl 6911 [2001:888:2000:d::a6]:56313
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40728

Show key headers only | View raw


On Thu, Mar 7, 2013 at 8:23 PM, Sven <svenito@gmail.com> wrote:
> 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.

Check out itertools.cycle, it should do what you want.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: iterating over a list as if it were a circular list Chris Angelico <rosuav@gmail.com> - 2013-03-07 20:28 +1100

csiph-web