Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89469
| 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 | <fomcl@yahoo.com> |
| 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 <fomcl@yahoo.com> |
| Reply-To | Albert-Jan Roskam <fomcl@yahoo.com> |
| To | Peter Otten <__peter__@web.de>, "python-list@python.org" <python-list@python.org> |
| In-Reply-To | <mhlh2f$plv$2@ger.gmane.org> |
| References | <87h9s1zoap.fsf@Equus.decebal.nl> <mhlh2f$plv$2@ger.gmane.org> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.49.1430167261.3680.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
----- Original Message -----
> From: Peter Otten <__peter__@web.de>
> To: python-list@python.org
> Cc:
> Sent: Monday, April 27, 2015 4:28 PM
> Subject: Re: Wrote a memoize function: I do not mind feedback
>
> Cecil Westerhof wrote:
>
>> 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
>>
>> I love to hear what you think of it.
>>
>> And ideas for other functionalities are welcome also. Übung macht den
>> Meister.
>
> See also:
>
> https://docs.python.org/dev/library/functools.html#functools.lru_cache
>
> A bit hard to find unless you already know it's there.
If you Google for memoization decorator, you will easily find many more implementations. 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 Cookbook, where he uses a mutable default argument {a dictionary} to implement memoization. I believe I went like this:
def some_func(arg, _memoize={}):
try:
return _memoize[arg]
except KeyError:
result = some_expensive_operation(arg)
_memoize[arg] = result
return result
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Wrote a memoize function: I do not mind feedback Cecil Westerhof <Cecil@decebal.nl> - 2015-04-27 15:35 +0200
Re: Wrote a memoize function: I do not mind feedback Peter Otten <__peter__@web.de> - 2015-04-27 16:28 +0200
Re: Wrote a memoize function: I do not mind feedback Albert-Jan Roskam <fomcl@yahoo.com> - 2015-04-27 20:35 +0000
Re: Wrote a memoize function: I do not mind feedback Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:06 +0200
Re: Wrote a memoize function: I do not mind feedback Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 01:02 -0600
Re: Wrote a memoize function: I do not mind feedback Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 10:04 +0200
Re: Wrote a memoize function: I do not mind feedback Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 09:58 +0100
Re: Wrote a memoize function: I do not mind feedback Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 13:52 +0200
csiph-web