3 ms·
Python has it too: * foo.get(bar) will return None if the element is not there * foo.get(bar, "beebop") does what your Scala example does * foo.setdefault work
by koenigdavidmj 16y ago
Python has it too:
* foo.get(bar) will return None if the element is not there
* foo.get(bar, "beebop") does what your Scala example does
* foo.setdefault works just like foo.get. However, if foo did not have key bar when it was called, it will fill the key in with the default value before returning.
* collections.defaultdict is also worth a look.