Where is the Python Journal?

William Annis annis at biostat.wisc.edu
Wed Feb 16 15:08:54 EST 2000


chris patti <cpatti at atg.com> writes:

> poorly understood and badly documented Perl topics) recently wrote
> a series of articles on 'memoization' - the use of recursion and
> recursive data structures to implement caching algorithms that save 
> huge gots of time on repeated computations..
> 
> Python needs something similar.

        I couldn't resist, largely because I thought it was so cute
when I came up with this after a little thought:

class memoize:
    def __init__(self, fn):
        self.fn = fn
        self.args = {}

    def __call__(self, *args):
        if not self.args.has_key(args):
            self.args[args] = apply(self.fn, args)

        return self.args[args]

if __name__ == '__main__':
    import math

    msin = memoize(math.sin)
    print msin(0), msin(math.pi/2), msin(math.pi/4)
    # Continue abusing to your heart's content...

        But, I agree about the Python journal idea and I'm also in the
same boat: getting the Perl Journal despite my apostasy.  I suppose we
shouldn't whine unless we intend to write articles, too. :)

-- 
William Annis - System Administrator - Biomedical Computing Group
annis at biostat.wisc.edu                       PGP ID:1024/FBF64031
Mi parolas Esperanton - La Internacia Lingvo    www.esperanto.org



More information about the Python-list mailing list