En Thu, 29 Mar 2007 19:44:56 -0300, Paddy <[EMAIL PROTECTED]>
escribió:
> On Mar 29, 8:49 am, [EMAIL PROTECTED] (Alex Martelli) wrote:
>> >>> foo = ["spam", "eggs", "spam", "spam", "spam", "beans", "eggs"]
>> >>> max(foo, key=foo.count)
>>
>> 'spam'
>
> This doesn't call foo.count for duplicate entries by keeping a cache
>
>>>> foo = ["spam", "eggs", "spam", "spam", "spam", "beans", "eggs"]
>>>> def cachecount(x, cache={}):
> ... return cache.setdefault(x, foo.count(x))
Unfortunately it does, because all arguments are evaluated *before* a
function call, so you gain nothing.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list