a_list.count(a_callable) ?
Evan Klitzke
evan at yelp.com
Sat Jun 16 20:38:06 EDT 2007
On 6/16/07, Dustan <DustanGroups at gmail.com> wrote:
> On Jun 16, 3:37 pm, Dustan <DustanGro... at gmail.com> wrote:
> > 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)
>
> I need to learn to think things through before hitting the send button
> (or test my examples); none of the mistakes I've made on this thread
> have been from ignorance.
>
> If a_function returns a true value other than True or the number 1
> (which are technically the same), it is not 'equal' to True. Either
If you're _really_ pedantic, 1 and True are _not_ the same, and this
can be an important distinction in some situations.
>>> 1 == True
True
>>> 1 is True
False
--
Evan Klitzke <evan at yelp.com>
More information about the Python-list
mailing list