I have a flat list, for example:
flat = ['1', '1-1', '1-1-1', '1-2', '2', '2-1', '2-2', '3']
that I need to convert to a nested list, where each level (dash followed by a number) starts a new sublist, for example:
result = ['1', ['1-1', ['1-1-1'], '1-2'], '2', ['2-1', '2-2'], '3']
Any tips how to do that in Python?
Example: