The dict
‘s get()
method takes an optional second parameter that can be used to provide a default value if the requested key is not found:
foo[bar] = foo.get(bar, 0) + 1
The dict
‘s get()
method takes an optional second parameter that can be used to provide a default value if the requested key is not found:
foo[bar] = foo.get(bar, 0) + 1