Le 17/01/2012 01:53, Kris Kowal a écrit :
For what it’s worth, Python dictionaries have .get(key, default) and
.setdefault(key, default). The former is non-mutating. Its behavior
is also different depending on arguments length. If the default is
not passed, it will throw an exception. If a default is passed, even
if that default is None, it will not throw an exception. I’ve found
both forms useful.
A use case I have in my case is that the "default value" may be
different. For instance, generating a new number. I think that
generators could do the trick here, but when using a generator as the
"default" argument of .setDefault, how can the engine tell if i want it
to use the generator as value or as value generator?
David
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss