Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44215
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'programmer': 0.03; 'executes': 0.09; 'resume.': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'anyway': 0.14; "'break'": 0.16; 'email addr:udel.edu>': 0.16; 'email name:<tjreedy': 0.16; 'iterator': 0.16; 'nest': 0.16; 'reedy': 0.16; 'statement.': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'received:209.85.217': 0.29; 'message-id:@mail.gmail.com': 0.30; 'terminate': 0.31; 'could': 0.34; 'received:209.85': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'surely': 0.36; 'done': 0.36; 'subject:?': 0.36; 'received:209': 0.37; 'clear': 0.37; 'skip:& 10': 0.38; 'rather': 0.38; 'break': 0.61; 'first': 0.61; 'effectively': 0.66; 'clearer': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=oh35bbnIK7GcQjN7hDH12AVtKXn271MGhAJrmWlMRDg=; b=xtV2m2natbbLT+VLpVs13zbcD91vR5OPws/wgb3PiUN5Xho4fiTml6vmDN2PspyecA fAt0R+xGMVcqPHZA4AhSaYiw87cL3TK8KsV75mntcWH7lwsixYanaiKNYIDL6mTcNOIq zeKWx5dxzT5t30LeMIAJwWvTd3B1Tc7DwOCWqgM70alWUjpFg2yYb84FzVw7hBbi2UVM KAhF/sOBBNmOxnF83VvkPnqdPhC/Af9q/vfBmeYCNqgrfflCEe7l+o0N9y2fQ1OupCm1 Vj3PU6IiCu7cgkLyqQYke9zKdnY0ZquFA5zSadpNs5Yjgwq+KIKa1+PDJEeblatIX/Fc cdjg== |
| X-Received | by 10.112.149.200 with SMTP id uc8mr3819701lbb.9.1366751689171; Tue, 23 Apr 2013 14:14:49 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <kl6s4b$23u$1@ger.gmane.org> |
| References | <kl6a1f$k2l$1@panix2.panix.com> <kl6s4b$23u$1@ger.gmane.org> |
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
| Date | Tue, 23 Apr 2013 22:14:09 +0100 |
| Subject | Re: Nested iteration? |
| To | Terry Jan Reedy <tjreedy@udel.edu> |
| Content-Type | multipart/alternative; boundary=047d7b342d74edea2704db0dacc4 |
| Cc | python-list <python-list@python.org> |
| 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.994.1366751696.3114.python-list@python.org> (permalink) |
| Lines | 73 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1366751696 news.xs4all.nl 2304 [2001:888:2000:d::a6]:44621 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44215 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 23 April 2013 21:49, Terry Jan Reedy <tjreedy@udel.edu> wrote: > ri= iter(range(3)) > for i in ri: > for j in ri: > print(i,j) > # this is somewhat deceptive as the outer loop executes just once > 0 1 > 0 2 > > I personally would add a 'break' after 'outer_line = next(f)', since the > first loop is effectively done anyway at that point, and dedent the second > for statement. I find to following clearer > > ri= iter(range(3)) > for i in ri: > break > for j in ri: > print(i,j) > # this makes it clear that the first loop executes just once > 0 1 > 0 2 > > I would only nest if the inner loop could terminate without exhausting the > iterator and I wanted the outer loop to then resume. > Surely a normal programmer would think "next(ri, None)" rather than a loop that just breaks.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Nested iteration? roy@panix.com (Roy Smith) - 2013-04-23 11:40 -0400
Re: Nested iteration? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 17:05 +0100
Re: Nested iteration? Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-23 10:05 -0600
Re: Nested iteration? Peter Otten <__peter__@web.de> - 2013-04-23 18:15 +0200
Re: Nested iteration? Chris Angelico <rosuav@gmail.com> - 2013-04-24 02:21 +1000
Re: Nested iteration? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 16:35 +0000
Re: Nested iteration? Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-23 10:30 -0600
Re: Nested iteration? Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-23 10:39 -0600
Re: Nested iteration? Chris Angelico <rosuav@gmail.com> - 2013-04-24 02:42 +1000
Re: Nested iteration? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 16:53 +0000
Re: Nested iteration? Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-23 16:49 -0400
Re: Nested iteration? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-04-23 22:14 +0100
Re: Nested iteration? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 22:29 +0100
Re: Nested iteration? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-04-23 22:41 +0100
Re: Nested iteration? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 23:42 +0100
csiph-web