I have a dictionary in Python where keys are paths. For instance:
dict["/A"] = 0
dict["/A/B"] = 1
dict["/A/C"] = 1
dict["/X"] = 10
dict["/X/Y"] = 11
I was wondering what a good way to print all the “subpaths” using any key.
For example, for a function called "print_dict_path" that does this, something like
print_dict_path("/A")
or
print_dict_path("/A/B")
will output something like:
"B" = 1
"C" = 1
The only method I can think of is something like using a regular expression and going through the entire dictionary, but I'm not sure if this is the best method (and I am not good at regular expression).
Thanks for any help.
source
share