Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'python.': 0.02; 'subject:not': 0.03; 'argument': 0.05; 'cache': 0.07; 'decorator': 0.09; 'function:': 0.09; 'sure,': 0.09; 'try:': 0.09; 'url:github': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; 'mutable': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'to:name:python-list@python.org': 0.22; 'url:dev': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'function': 0.29; 'went': 0.31; 'keyerror:': 0.31; 'there.': 0.32; 'url:python': 0.33; '-----': 0.33; 'monday,': 0.33; 'skip:_ 10': 0.34; 'except': 0.35; 'but': 0.35; 'google': 0.35; 'url:org': 0.36; 'email addr:python.org': 0.37; 'easily': 0.37; 'feedback': 0.38; 'implement': 0.38; 'url:library': 0.38; 'to:addr:python- list': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'received:98.137': 0.60; 'here:': 0.62; 'show': 0.63; 're:': 0.63; 'hear': 0.63; 'more': 0.64; 'love': 0.65; 'email name:python- list': 0.65; 'header:Reply-To:1': 0.67; 'believe': 0.68; 'percent': 0.68; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; 'default': 0.69; 'received:98.136': 0.69; '100': 0.79; '2015': 0.84; 'otten': 0.84; 'received:bullet.mail.gq1.yahoo.com': 0.84; 'fibonacci': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1430167124; bh=K0OBs1I3Pu3JGO+yyPvCJPRURubpNGz0rX3Ti359uY0=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=XPgcp9ZYp9+9JVMXGW/kTcY3fyNXvg2UB6jY/8wx/ckT5duBE4B1iVUFaVDb9Is9WYLFpa5FO0vkTZSOKNryj7zlIAydHGFb1oBj5Yq1lY8/FjInQ0WmfvC2bcDL5lTj+/XPBPZr07dhlGl1wIXPRKY95tlfvod7auqzTympR1eJfKQ59sr2sHVyVJllGJZzQOIk3/9+AdoqbcrSzcq9lKpGZgY/R5A32Dw3WHsIKRKZMWdKdZnhvxjRXkXpIP9Uo2ieP5oJkr3FCqGLHjVM60KbYj4+MeLyrlhtgFc1BffXktvT7+09mpbRy677sZdt6N4FnwRjva8vYrv12GzCBQ== X-Yahoo-Newman-Property: ymail-4 X-Yahoo-Newman-Id: 109334.39031.bm@omp1053.mail.gq1.yahoo.com X-YMail-OSG: Y3G4rUMVM1lXvk_b6nFPmHTWsdvkQpTroD.QM_ktWJktUJW_WNN97zwfVTC3KWd 7NiV0R7PjafwUIahcI3kIBXBQArdy2UE0s8Iap.8FMPFDylPRMQvsnY0A3CtF7waMhDwIwqTigr6 gP4HEb9QbWSB28VR53ygUQYpbc2BwtTHY1hWydMgmMylZwh8mUlA8jUh0S15WYOVVnBR_de1MPWA 2EdjoPHSkvazYERbijqjm1aRQLmYB6OPljy2g7dbr5PLP0cmTchgIlKWeu7C_zF6XYlmyH0mghwH Yuo1mypyz0pqc9eGuZFXVpU0PcVFxD9HLPkBDoxUQww6Eoeh3ysWl2MVo5sQE8p4r08qR7aOHQdC HjSlrp34bJ2GRSc2kWNHJGMQZHLPtB3L0vrBdkGBhBLlIE.dizpxxvvKyujaomBSKYqmaYb2QgpZ BxeIToXdxnqBgkABcMoGcjrIX1rgaU8._kQHx2w39byWsN7LwVTIT5RbmuMqWFq0pYFbjIY9XeX3 8g87Qe9BG4J2bftQ- Date: Mon, 27 Apr 2015 20:35:18 +0000 (UTC) From: Albert-Jan Roskam Reply-To: Albert-Jan Roskam To: Peter Otten <__peter__@web.de>, "python-list@python.org" In-Reply-To: References: <87h9s1zoap.fsf@Equus.decebal.nl> Subject: Re: Wrote a memoize function: I do not mind feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430167261 news.xs4all.nl 2910 [2001:888:2000:d::a6]:57217 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89469 ----- Original Message ----- > From: Peter Otten <__peter__@web.de> > To: python-list@python.org > Cc:=20 > Sent: Monday, April 27, 2015 4:28 PM > Subject: Re: Wrote a memoize function: I do not mind feedback >=20 > Cecil Westerhof wrote: >=20 >> I started again with Python. In Clojure you have memoize. I thought it >> nice to have this in Python also. So I wrote it. With a Fibonacci >> function to show the usefulness. >> You can find it here: >> https://github.com/CecilWesterhof/PythonLibrary >>=20 >> I love to hear what you think of it. >>=20 >> And ideas for other functionalities are welcome also. =C3=9Cbung macht = den >> Meister. >=20 > See also:=20 >=20 > https://docs.python.org/dev/library/functools.html#functools.lru_cache >=20 > A bit hard to find unless you already know it's there. If you Google for memoization decorator, you will easily find many more imp= lementations. Not 100 percent sure, but I think the LRU cache decorator was= not exactly light weight. I also like this one from Martelli's Python Cook= book, where he uses a mutable default argument {a dictionary} to implement = memoization. I believe I went like this: def some_func(arg, _memoize=3D{}): try: return _memoize[arg] except KeyError: result =3D some_expensive_operation(arg) _memoize[arg] =3D result return result