On Mar 30, 10:17 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > 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
I had to experiment to find out what you meant but I finally got it. that call to foo.count in the setdefault is *always* called. Forgive my senility. - Paddy. -- http://mail.python.org/mailman/listinfo/python-list