4 ms·
For what it's worth, mutable default parameters do have their use. def foo(x, cache = {}): value = cache.get(x) if value is None:
by boothby 3y ago
For what it's worth, mutable default parameters do have their use.
def foo(x, cache = {}):
value = cache.get(x)
if value is None:
...
cache[x] = value
return value
This simple example, thankfully, is obviated by the @cache decorator as of py3.9, but I still occasionally find uses for the feature.