Need to turn x:
X = [[\'A\', \'B\', \'C\'], [\'A\', \'B\', \'D\']]
Into Y:
Y = {\'A\': {\'B\': {\'C\',\'D\'}}}
There is a logical inconsistency in your problem statement. If you really want
['xyz/123/file.txt', 'abc/456/otherfile.txt']
to be changed to
{'xyz': {'123': 'file.txt}, 'abc': {'456': 'otherfile.txt'}}
Then you have to answer how a path 'abc.txt' with no leading folder would be inserted into this data structure. Would the top-level dictionary key be the empty string ''
?