This function is for two keys:
def get(keyA, keyB)
return mydict[keyA][keyB]
How can I write the following function for variable number of keys?
def get(*keys)
return mydict[keys[0]][keys[1]][keys[3]]...
This function is for two keys:
def get(keyA, keyB)
return mydict[keyA][keyB]
How can I write the following function for variable number of keys?
def get(*keys)
return mydict[keys[0]][keys[1]][keys[3]]...
Iterate keys, and assign the item as you iterate:
def get(*keys):
ret = mydict
for key in keys:
ret = ret[key]
return ret