A bit weird dictionary behavior

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Sep 22 10:35:50 EDT 2008


Tino Wildenhain:

> Wouldn't
> len([x for x in iterable if x==y])
> or even shorter:
> iterable.count(y)
> not work and read better anyway?

The first version creates an actual list just to take its length,
think about how much memory it may use.
The second version requires the 'iterable' object to have a count()
method, and in general this is false.


> 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.

I don't understand.

Bye,
bearophile



More information about the Python-list mailing list