I have formatted all my university notes as follows:
CourseName: {
Part 1: {
I.I - Intro: {
Topic1: {
descr1;
descr2: {
2.a;
2.b;
2.c.
};
descr3.
};
Topic2: {
descr: {
example.
}.
}.
};
I.II - NextChapter: {
Topic3: {
whatever.
}.
}.
};
Part 2: {
II.I - FinalChapter: {
content.
}.
}.
}
I'd like to structure them into a Tree data structure and I've tried doing so, both recursively and iteratively, in the past hours, doing many researches online, but none of my attempts at it is working.
I've already implemented a Node class (with self.__value and a list self.__children and all the useful methods you would expect from it) as well as a Tree class (with self.__nodes as a dictionary and other utility methods), so feel free to use methods such as add_node or add_child in any form of your liking in your answers.
What I'm struggling with is to understand how to structure the function def parseTree(s, l) - that ideally takes as inputs a string s (my notes) and a list l establishing the delimiters i.e. [":{", ";", "}."] or ["{","}"] or similar - and returns a tree object, with each node having as value the text preceding :{ and a list of children (if any) separated by ; in the text.
Any suggestion?