False and 0 in the same dictionary

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Nov 5 13:55:28 CET 2008


On Wed, 05 Nov 2008 04:22:32 -0800, bearophileHUGS wrote:

> In Python if bools become distinct from integers you have to rewrite
> things like:
> sum(el == val for el in iterable)
> as:
> sum(1 for el in iterable if el == val)

I would expect that you can still "cast" `bool`\s to `int`\s then.  
Sometimes I write it as

sum(int(el == val) for el in iterable)

just for clarity what the intent is.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list