a_list.count(a_callable) ?
Carsten Haese
carsten at uniqsys.com
Fri Jun 15 14:51:27 EDT 2007
On Fri, 2007-06-15 at 14:39 -0400, Carsten Haese wrote:
> class WhereTrue(object):
> def __init__(self, func):
> self.func = func
> def __eq__(self, other):
> return self.func(other)
>
> list1.count(WhereTrue(callable1))
> list2.count(WhereTrue(callable2))
P.S: Note, however, that this will only work if the list elements don't
define __eq__ methods themselves. If they do, their __eq__ methods get
called instead of WhereTrue's __eq__ method, leading to incorrect
results.
--
Carsten Haese
http://informixdb.sourceforge.net
More information about the Python-list
mailing list