Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40733 > unrolled thread
| Started by | Chris Rebert <clp2@rebertia.com> |
|---|---|
| First post | 2013-03-07 01:31 -0800 |
| Last post | 2013-03-07 01:31 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: iterating over a list as if it were a circular list Chris Rebert <clp2@rebertia.com> - 2013-03-07 01:31 -0800
| From | Chris Rebert <clp2@rebertia.com> |
|---|---|
| Date | 2013-03-07 01:31 -0800 |
| Subject | Re: iterating over a list as if it were a circular list |
| Message-ID | <mailman.2998.1362648719.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Mar 7, 2013 1:24 AM, "Sven" <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) <= 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
Back to top | Article view | comp.lang.python
csiph-web