On Tue, 26 Feb 2008 06:02:12 -0800, bearophileHUGS wrote:

> This is a real difference, that has real impact on the programs I
> write, so I often use the if/else approach, despite the dict.get()
> method being semantically fitter and shorter.
> So can the dict.get() method be speed up? And if not, why?

I guess it's the method lookup that's the slow part.  Factor it out of the
loop and measure again::

    adict_get = adict.get
    for _ in xrange(M):
        for k in keys1:
            r = adict_get(k, None)
        for k in keys2:
            r = adict_get(k, None)

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to