Is there a clever way to pass the key to defaultdict's default_factory?
- by Paul Oyster
A class has a constructor which takes one parameter:
class C(object):
def __init__(self, v):
self.v = v
...
Somewhere in the code, it is useful for values in a dict to know their keys.
I want to use a defaultdict with the key passed to newborn default values:
d = defaultdict(lambda : C(here_i_wish_the_key_to_be))
Any suggestions?