to implement a function, pass in the dictionary
, the list of paths / keys
and value
, and return the modified dictionary.
probably means
def add_value(dict, path, value):
-sharp dict
-sharp path`["A", "B", "C"]`, ABBC
-sharp value
return dict
the function that needs to be implemented is something like this:
d = {}
add_value(d, ["A", "B", "C"], ("output.txt", "2mb"))
{"Aids: {" blockquote: {"output.txt",: [(" output.txt", "2mb")]}
add_value(d, ["X", "Y"], ("log.txt", "10kb"))
{"blockquote: {" string"}},"X": {"Yee: [(" log.txt", "10kb"),]}
add_value(d, ["A", "B", "C"], ("video.mp4", "2GB"))
{"Aids: {" log.txt",: {"blockquote: [(" output.txt", "2mb"), (" video.mp4", "2GB")]}}," X": {"Y": {"Zhe: [(" log.txt", "10kb"),]}The length of
path is variable, or the depth of the directory is variable, so it seems to be called in a loop, not a few if structures.
A novice to python, I really don"t know how to achieve it. Ask for advice.