A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-April/034932.html below:

summing a bunch of numbers (or "whatevers")

[Python-Dev] Fwd: summing a bunch of numbers (or "whatevers") [Python-Dev] Fwd: summing a bunch of numbers (or "whatevers")Tim Peters tim.one@comcast.net
Tue, 22 Apr 2003 23:59:27 -0400
[Greg Ward]
> Hmmm, a random idea: has filter() ever been used for anything else?
> I didn't think so.  So why not remove everything *except* that handy
> special-case: ie. in 3.0, filter(seq) == filter(None, seq) today, and
> that's *all* filter() does.
>
> Just a random thought...

It's been used for lots of other stuff, but I'm not sure if any other use
wouldn't read better as a listcomp.  For example, from spambayes:

def textparts(msg):
    """Return a set of all msg parts with content maintype 'text'."""
    return Set(filter(lambda part: part.get_content_maintype() == 'text',
                      msg.walk()))

I think that reads better as:

    return Set([part for part in msg.walk()
                     if part.get_content_maintype() == 'text'])

In Python 3.0 that will become a set comprehension <wink>:

    return {part for part in msg.walk()
                 if part.get_content_maintype() == 'text'}





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4