'How to make a dict point to and get to "follow" and get all possible path combinations?

How to make a dict point to and get to "follow" and get all possible combinations of path (I kind of wanted to know the logic behind it) Example :

{1: [3, 8, 15], 2: [7, 14], 3: [1, 6, 13], 4: [5, 12], 5: [4, 11], 6: [3, 10], 7: [2, 9], 8: [1], 9: [7], 10: [6, 15], 11: [5, 14], 12: [4, 13], 13: [3, 12], 14: [2, 11], 15: [1, 10]}

here 1 points to 3, 8, 15 (path terminates if it reaches a checkpoint it has reached before) so the path looks like :

1 - > 3
1 - > 8 # End
1 -> 15

3, 8, 15 points to (6, 13), (), (10) respectively making it

1 -> 3 -> 6
1 -> 3 -> 13
1 -> 15 -> 10

This leads to :

1 -> 3 -> 6 -> 10
1 -> 3 -> 13 -> 12
1 -> 15 -> 10 -> 6

How to do this but automatically, maybe like a function which takes a dict and returns all the path combinations like this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source