A bit weird dictionary behavior

Tino Wildenhain tino at wildenhain.de
Mon Sep 22 16:14:05 CEST 2008


Hi,

bearophileHUGS at lycos.com wrote:
> Pekka Laukkanen:
...
> On the other hand it has some little practical advantages, you can do:
> sum(x == y for x in iterable)
> 
> That also equals to a more tidy:
> sum(1 for x in iterable if x == y)

Wouldn't
len([x for x in iterable if x==y])

or even shorter:

iterable.count(y)

not work and read better anyway?

even calculating with boolean values isn't neccessary
since 'and' and 'foo if bar else blub' are working much better
so the type coalescing

bool - int - float can really go away.

Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20080922/6af8e66d/attachment.bin>


More information about the Python-list mailing list