Feature suggestion -- return if true
Chris Angelico
rosuav at gmail.com
Sun Apr 17 00:31:06 EDT 2011
On Sun, Apr 17, 2011 at 2:21 PM, Gregory Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> My idiom for fetching from a cache looks like this:
>
> def get_from_cache(x):
> y = cache.get(x)
> if not y:
> y = compute_from(x)
> cache[x] = y
> return y
>
> which doesn't require any conditional returns.
There's not a lot of difference between conditionally returning and
conditionally executing all the code between here and the return,
except that when you string three conditional returns together by your
method, it gets three indentations.
Chris Angelico
More information about the Python-list
mailing list