I have lists where each entry is representing a nested structure, where / represents each level in the structure.
['a','a/b/a','a/b','a/b/d',....]
I want to take such a list and return an index list where each level is sorted in alphabetical order.
If we had the following list
['a','a/b','a/b/a','a/c','a/c/a','b']
It represents the nested structure
'a': #1
'b': #1.1
'a': ... #1.1.1
'c': #1.2
'a': ... #1.2.1
'b' : ... #2
I am trying to get the output
['1','1.1','1.1.1', '1.2','1.2.1','2']
But I am having real issue on how to tackle the problem, would it be solved recursively? Or what would be a way to solve this for any generic list where each level is separated by /? The list is originally not necessarily sorted, and each level can be any generic word.
/characters, and then iterate on the result. Initialize a variable to point to the root of the structure. Look up the first result in the root dictionary. if you don't find a key with the first character, then add a new key with{}(an empty dictionary) as the value. Then change the pointer to point to the dictionary for that character. Then consider the next character. Repeat until you run out of characters. When you're done, you'll have a structure that represents the output that you show.1,1.1, etc.