Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89531
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'cest': 0.09; 'exception.': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'url:blog': 0.10; 'def': 0.12; 'language.': 0.14; '(when': 0.16; 'cheap,': 0.16; 'dict': 0.16; 'necessary).': 0.16; 'raised.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'suppose.': 0.16; 'exception': 0.16; 'do,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'trying': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'url:02': 0.24; 'wednesday': 0.24; 'gets': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; "doesn't": 0.30; 'code': 0.31; '>>>>': 0.31; 'exceptions': 0.31; 'keyerror:': 0.31; 'url:06': 0.31; 'probably': 0.32; 'skip:_ 10': 0.34; 'except': 0.35; 'monday': 0.35; 'but': 0.35; 'useful': 0.36; 'performance': 0.37; 'to:addr:python-list': 0.38; 'expensive': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ian': 0.60; "you're": 0.61; 'our': 0.64; 'linked': 0.65; 'charset:windows-1252': 0.65; '2015': 0.84; 'compare:': 0.84; 'received:2': 0.84; 'url:2013': 0.84; 'anymore,': 0.95 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: Wrote a memoize function: I do not mind feedback |
| Date | Wed, 29 Apr 2015 09:58:44 +0100 |
| References | <87h9s1zoap.fsf@Equus.decebal.nl> <mhlh2f$plv$2@ger.gmane.org> <mailman.49.1430167261.3680.python-list@python.org> <87y4lbxyc2.fsf@Equus.decebal.nl> <mailman.74.1430291009.3680.python-list@python.org> <87d22nxsvu.fsf@Equus.decebal.nl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | host-2-98-195-171.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| In-Reply-To | <87d22nxsvu.fsf@Equus.decebal.nl> |
| 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.76.1430297954.3680.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430297954 news.xs4all.nl 2904 [2001:888:2000:d::a6]:51211 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89531 |
Show key headers only | View raw
On 29/04/2015 09:04, Cecil Westerhof wrote:
> Op Wednesday 29 Apr 2015 09:02 CEST schreef Ian Kelly:
>
>> On Wed, Apr 29, 2015 at 12:06 AM, Cecil Westerhof <Cecil@decebal.nl> wrote:
>>> Op Monday 27 Apr 2015 22:35 CEST schreef Albert-Jan Roskam:
>>>> def some_func(arg, _memoize={}):
>>>> try:
>>>> return _memoize[arg]
>>>> except KeyError:
>>>> result = some_expensive_operation(arg)
>>>> _memoize[arg] = result
>>>> return result
>>>
>>> That is in a way the same as what I do, except I do not use an
>>> exception. Iunderstand it is not as expensive as it was anymore,
>>> but I do not like to use an exception (when not necessary).
>>
>> It's useful to keep in mind which case it is that you're trying to
>> optimize. The expensive case for exceptions is when one actually
>> gets raised. A try that doesn't raise an exception is pretty cheap,
>> probably cheaper than looking up the key in the dict twice as the
>> code you linked does. Compare:
>
> It is not only performance wise, I find the code without the try also
> better looking. But that is very personally I suppose.
>
You might find this interesting
http://www.jeffknupp.com/blog/2013/02/06/write-cleaner-python-use-exceptions/
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
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