3 ms·
They have to, because they cannot, in general, decide whether the lambda you gave it is idempotent _and_ returns an immutable value. For example, if you provid
by Someone 13y ago
They have to, because they cannot, in general, decide whether the lambda you gave it is idempotent _and_ returns an immutable value.
For example, if you provide a function that returns an empty list, and do:
l = foo['bar']
l.append('baz')
print len(foo['bar'])
That should print 2 (apologies if this isn't correct Python)
If one had a defaultdict that took a default value in a language with enough reflection, you might be able to deduce that the lambda always returns a simple value such as 3.1415927, and not store copies in the dictionary.
- maxerickson 13y agoWhat you have there will print 1.
- deleted 13y ago[deleted]