> So How should I call this:
>
> class ...dict(dict):
> def __init__(self, fun):
> self.fun = fun
>
> def __missing__(self, key):
> return self.fun(key)
I don't know how you should,
but I tried the following
which seems to work
class KeyPlusOne( dict ) :
def __
Op 03-11-14 om 12:09 schreef Chris Angelico:
> On Mon, Nov 3, 2014 at 10:04 PM, Antoon Pardon
> wrote:
>> Is it possible to have a default dictionary where the default is dependant
>> on the key?
>>
>> I was hoping something like this might work:
> m = defaultdict(lambda key: key+1)
>> But it
On Mon, Nov 3, 2014 at 10:04 PM, Antoon Pardon
wrote:
> Is it possible to have a default dictionary where the default is dependant
> on the key?
>
> I was hoping something like this might work:
m = defaultdict(lambda key: key+1)
>
> But it obviously doesn't:
m[3]
>
> Traceback (most rece
Is it possible to have a default dictionary where the default is dependant
on the key?
I was hoping something like this might work:
>>> m = defaultdict(lambda key: key+1)
But it obviously doesn't:
>>> m[3]
Traceback (most recent call last):
File "", line 1, in
TypeError: () takes exactly 1 ar