3 ms·
You do know about `.get()`, right? if `a = {'a': 1, 'b': 2}`, and I do `cval = a.get('c', 3)`, `cval` will contain 3. If I do `cval = a['c']`, I get an except
by WhyCause 5y ago
You do know about `.get()`, right?
if `a = {'a': 1, 'b': 2}`, and I do `cval = a.get('c', 3)`, `cval` will contain 3.
If I do `cval = a['c']`, I get an exception
- prepend 5y agoYes, I think this is how default dict is implemented. The issue here is that the clients have to know the particular default values for each parameter. For me, it was easier to return a defaultdict where the callers didn’t need to know what default value to pass into their gets.