by zo1 · 12y ago · 0 comments
And they pretty much say that there is only one method that's been overridden from the normal dict class. And all it does is it executes the anonymous method (lamda) you supplied instead of returning the default value you pass in.
Also, this depends on your usage, and what you have in the lambda expression. I'm curious about your code, care to paste/link some of it for us?
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.
>>> import collections
>>> dd = collections.defaultdict(int)
>>> print dd['doesnt exist']
0
>>> print dd
defaultdict(<type 'int'>, {'doesnt exist': 0})