On Jun 16, 12:04 pm, Wildemar Wildenburger <[EMAIL PROTECTED]>
wrote:
> class SmartCountingList(list):
>     def count(self, item, func=lambda x: x):
>         return len([item for item in self if func(item) is True])

A less bug-prone and (I would think) speedier example, although still
untested:

class SmartCountingList(list):
    def count(self, item, func=lambda x: x):
        return sum(1 for i in self if func(item)==item)

Then, you would call it as follows:
a_list.count(True, a_function)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to