I have a nested dictionary, i.e.
a={'k1':{'k2':1}}
I would like to write a function
def f(dictionary,key_list):
pass
such that f(a,['k1','k2']) would be equivalent to del(a['k1']['k2'])
I tried to use
from functools import reduce
import operator
def f(dictionary,key_list):
reduce(operator.delitem,key_list,dictionary)
However
f(a,['k1','k2'])
returns
TypeError: 'NoneType' object does not support item deletion
operator.delitemreturnsNone.