Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40727
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <svenito@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.013 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'empty,': 0.09; 'iterate': 0.09; 'assume': 0.11; 'to:name:python-list': 0.15; 'duplicating': 0.16; 'early.': 0.16; 'points:': 0.16; 'pythonic': 0.16; 'element': 0.17; 'items.': 0.17; 'keyboard': 0.22; "i'd": 0.22; '>': 0.23; 'elements': 0.23; "i've": 0.23; 'seems': 0.23; 'random': 0.24; 'wondering': 0.26; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'subject:list': 0.28; 'run': 0.28; 'restart': 0.29; 'points': 0.29; 'skip:& 10': 0.29; 'point': 0.31; 'received:74.125.82': 0.33; 'to:addr:python-list': 0.33; 'point.': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'but': 0.36; 'wanted': 0.36; 'received:74.125': 0.36; 'be.': 0.36; 'too': 0.36; 'far': 0.37; 'to:addr:python.org': 0.39; 'list,': 0.39; 'little': 0.39; 'most': 0.61; 'subject:over': 0.84; 'mean.': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=u32oEaa3JFOsQ2jRV9Y/I+vdFARU3++BkvJ8DT1ghLM=; b=jVSiIvDpx9azhdsr2LMXQGpo3uYAjZ7cySoJDgO6AE2ZMM62HtgQyXpkjFmmSd+phE a0eprUNpTaMpw1mLPI1uU5BV/D2B6akFZDdfpg3xHZjn7Z8utgblT3FInDVGOMdKlOFk 8fIdM7J9v9G0VEWxb5LUoJG8XMR9t0YcT+adagv87w9ptRH3mSQqyyBpwX0gT0DYBGsn 4z4o9N2Ka6t1CTlMxhzmcUvnnXZPJm++/xWlvgfCQkBOW/hzoZ/HabGZb3KqnoGUuSfz RV8Av6WZsRn4kFAK3L2WB3izEctTKL4ySWAX241k22SkB6055e0gRVT4I9qLq6Rv7vZ2 cOkQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.194.6.2 with SMTP id w2mr52676526wjw.10.1362648462657; Thu, 07 Mar 2013 01:27:42 -0800 (PST) |
| Date | Thu, 7 Mar 2013 09:27:42 +0000 |
| Subject | iterating over a list as if it were a circular list |
| From | Sven <svenito@gmail.com> |
| To | python-list <python-list@python.org> |
| Content-Type | multipart/alternative; boundary=047d7b5d2e209214d704d752516d |
| 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.2994.1362648463.2939.python-list@python.org> (permalink) |
| Lines | 64 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1362648463 news.xs4all.nl 6926 [2001:888:2000:d::a6]:56071 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:40727 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Stupid keyboard shortcuts, sent it too early. Apologies
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.
So far I've got (pseudo code)
i = 0
for point in points:
put N[i] at point
if i > len(N):
i = 0
is this the most pythonic way to accomplish this?
Additionally, what if I wanted to pull a random element from N, but I want
to ensure all elements from N have been used before starting to pick
already chosen random elements again.
So far I thought of duplicating the list and removing the randomly chosen
elements from the list, and when it's empty, re-copying it. But that seems
a little "wrong" if you know what I mean.
--
./Sven
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
iterating over a list as if it were a circular list Sven <svenito@gmail.com> - 2013-03-07 09:27 +0000
Re: iterating over a list as if it were a circular list Alexander Blinne <news@blinne.net> - 2013-03-08 00:49 +0100
Re: iterating over a list as if it were a circular list Alexander Blinne <news@blinne.net> - 2013-03-08 00:50 +0100
Re: iterating over a list as if it were a circular list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-08 17:59 +0000
csiph-web