(test) ? a:b

MRAB python at mrabarnett.plus.com
Mon Oct 27 02:40:29 CET 2014

```On 2014-10-27 00:38, Ben Finney wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
>
>> Do you really not see the connection between counting and summing?
>
> Connection? Of course. But I also see a huge distinction. I'm surprised
> you could misunderstand my position to the extent you think such a
> question needs to be asked.
>
> The difference between “sum these values” versus “count these values” is
> important. That's at the root of why I find it confusingly wrong to sum
> True or False values.
>
> Do you really not see the distinction between counting and summing?
>
> The question is just as silly that way.
>
>> If you have three apples, and I have two apples, then in total we have
>> (count the apples: one two three, four five) five apples.
>
> If you have three apples in one basket, and I have two apples in one
> basket, “sum the baskets” is quite a different operation from “count the
>
>      [3, 2]
>
> What is the sum of those values?
>
> How many values are there?
>
Those are ints. The question is whether you can sum bools.

Python's way is to say that it's counting how many True there are.

Sometimes it's useful; pragmatism beats purity, and all that.

> The distinction between those is why I find it unhelpful to express “how
> many values?” with “sum them”.
>
>> Alas, you missed the bigger bug: I'm counting *blank lines*, not
>> non-blank lines. You need a `not` in there.
>
> Which is, shall we say, not incompatible with the position that the
> “count the matches by summing bools” method is an unclear expression of
> intent :-)
>

```