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


Groups > comp.lang.python > #10574

Re: removing nested iffs

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'line:': 0.09; 'none:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:removing': 0.09; 'am,': 0.13; 'wrote:': 0.15; 'cool!': 0.16; 'pairs:': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'argument': 0.16; 'def': 0.16; 'suggest': 0.17; 'literal': 0.23; 'sat,': 0.28; 'yield': 0.29; 'from:addr:web.de': 0.30; 'chris': 0.32; 'list': 0.32; 'break': 0.33; 'it.': 0.33; 'skip:" 20': 0.33; 'list.': 0.33; 'to:addr :python-list': 0.34; 'header:X-Complaints-To:1': 0.34; '...': 0.34; 'pretty': 0.35; 'received:org': 0.38; 'subject:: ': 0.38; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'peter': 0.62; '30,': 0.74; 'otten': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: removing nested iffs
Date Sat, 30 Jul 2011 09:15:51 +0200
Organization None
References <CAAAhF4GeXr+vxNCcJeHm1LfvTciqzSTrp0f3onx020PJSGh4MA@mail.gmail.com> <j0v60g$mci$1@dough.gmane.org> <CAPTjJmr0Fhf4BceRMNxCUqbN_13dZ7Bxfcqn0+jPLaamAxujJQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084ad49.dip.t-dialin.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.1653.1312010164.1164.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1312010164 news.xs4all.nl 23890 [2001:888:2000:d::a6]:49716
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10574

Show key headers only | View raw


Chris Angelico wrote:

> On Sat, Jul 30, 2011 at 6:42 AM, Peter Otten <__peter__@web.de> wrote:
>> def format_pairs(pairs):
>> for template, value in pairs:
>> if value is None:
>> break
>> yield template.format(value)
>>
> 
> Cool! May I suggest a trifling change:
> 
> def format_pairs(*pairs):
> for template, value in pairs:
> if value is None: break
> yield template.format(value)
> 
> That way, the call can dispense with the [] in the argument list. This
> is a pretty clean solution though, I like it.

Alternatively you can move the list literal into an extra line:

    pairs = [
        ...
    ]
    return "".join(format_pairs(pairs))

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


Thread

Re: removing nested iffs Peter Otten <__peter__@web.de> - 2011-07-30 09:15 +0200

csiph-web