On Nov 18, 8:45 pm, Phlip phlip2...@gmail.com wrote:
Pythonistas:
If everyone likes this post, then the code is a snippet for
community edification. Otherwise, it's a question: How to do this kind
of thing better?
I want a dict() variant that passes these test cases:
map = Map()
Pythonistas:
If everyone likes this post, then the code is a snippet for
community edification. Otherwise, it's a question: How to do this kind
of thing better?
I want a dict() variant that passes these test cases:
map = Map()
assert not(map.has_key('_default'))
map =
You may want to look at the collections.defaultdict class. It takes in a
factory function for default values.
You can also implement your class by overriding the __missing__ method of
the dict class, rather than overriding the __getitem__.
Both were added in Python 2.5 according to the