A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2004-April/044010.html below:

[Python-Dev] Re: PEP 318 bake-off?

[Python-Dev] Re: PEP 318 bake-off?Josiah Carlson jcarlson at uci.edu
Sat Apr 3 19:37:55 EST 2004
> ##########
> #
> # Decorations
> #
> class Memoized(dict):
>     """ A function wrapper to cache the results of functions that take a long
>         time to complete, like database querries or intensive mathematical
>         computations.
> 
>         To wipe the cache, just call m.clear()
>     """
>     def __init__(self, func, init={}):
>         """ Accepts the function to be memoized and an optional initial 
>             dictionary of known results.
>         """
>         dict.__init__(self, init)
>         self.func = func
> 
>     def __call__(self, *args, **kwds):
>         key = (args, tuple(kwds.items())) # hope everything's hashable...
>         return ( self.get(key)
>                  or self.setdefault(key, self.func(*args, **kwds)) )

I believe that with standard dictionaries, kwds is not guaraneed to have
any particular order.  Perhaps sorting kwds.items() makes sense?

 - Josiah


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4