Chris Angelico wrote: > On Sat, Jul 30, 2011 at 6:42 AM, Peter Otten <__pete...@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)) -- http://mail.python.org/mailman/listinfo/python-list