I have a strictly sorted list of strings:
['a',
'b',
'b/c',
'b/d',
'e',
'f',
'f/g',
'f/h',
'f/h/i',
'f/h/i/j']
This list is similar to tree representation. So, I need to convert it to dict:
{'a': {},
'b': {'c': {},
'd': {}},
'e': {},
'f': {'g': {},
'h': {'i': {'j': {}}}}}
As you can see, keys in this dict are parents and values are children.
UPD: I agree that empty dict is better than None
If you don’t insist on
Noneas the leaf value, you can use the compact codeAdmittedly, it isn’t that obvious what this code does, but it’s succinct 🙂