[Python-ideas] Where-statement (Proposal for function expressions)

Daniel Stutzbach daniel at stutzbachenterprises.com
Wed Jul 15 14:02:10 CEST 2009


On Wed, Jul 15, 2009 at 4:59 AM, Carl Johnson <
cmjohnson.mailinglist at gmail.com> wrote:

> total = sum(count for item in l) where:
>    count = item.size if item.size > 0 else 1
>
> It seems like for that case, we definitely want the "where" to apply
> every time the generator expression loops though, but… Is that
> feasible?
>

Unlikely, but this is:

total = sum(f(item) for item in lst) where:
    def f(item):
        return item.size if item.size > 0 else 1

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090715/3dc179ff/attachment.html>


More information about the Python-ideas mailing list