Strange behavior when passing a function as second parameter of the `setdefault` dictionary method
Strange behavior when passing a function as second parameter of the `setdefault` dictionary method Question: I don’t understand the behavior of setdefault in this scenario: def f(x): return x+1 dct = {5: 15} print(dct.setdefault(5, f(5))) The key 5 is in the dictionary, but instead of returning the value 15 immediately, it wastes time computing the …