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/2006-April/063406.html below:

[Python-Dev] tally (and other accumulators)

[Python-Dev] tally (and other accumulators) [Python-Dev] tally (and other accumulators)Alex Martelli aleaxit at gmail.com
Tue Apr 4 22:12:51 CEST 2006
On 4/4/06, Raymond Hettinger <python at rcn.com> wrote:
> [Alex]
> > This is quite general and simple at the same time: for example, it
> > was proposed originally to answer some complaint about any and all
> > giving no indication of the count of true/false items:
> >
> > tally(bool(x) for x in seq)
> >
> > would give a dict with two entries, counts of true and false items.
>
> FWIW, sum() works nicely for counting true entries:
>
>     >>> sum(x%3==0 for x in range(100))
>    34

Sure, and also works fine for counting false ones, thanks to 'not',
but if you need both counts sum doesn't work (not without dirty tricks
that can't be recommended;-).


Alex
More information about the Python-Dev mailing list

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