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


Groups > comp.lang.python > #10574

Re: removing nested iffs

From Peter Otten <__peter__@web.de>
Subject Re: removing nested iffs
Date 2011-07-30 09:15 +0200
Organization None
References <CAAAhF4GeXr+vxNCcJeHm1LfvTciqzSTrp0f3onx020PJSGh4MA@mail.gmail.com> <j0v60g$mci$1@dough.gmane.org> <CAPTjJmr0Fhf4BceRMNxCUqbN_13dZ7Bxfcqn0+jPLaamAxujJQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1653.1312010164.1164.python-list@python.org> (permalink)

Show all headers | 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