In Python when we are building a recursive algorithm that uses backtracking a mutable type such as a list is great to use. It can be modified at each call in our recursion tree, then returned back to it's original state once all children have been recurred on. See the image below for an example.
However, when using a mutable type such as an integer this is impossible. If we try to 'modify' an integer by using a reference to it in memory a new integer will be created. This makes it impossible to backtrack with immutable types.
What is the best practice way around this? We could store the integer in a list like this
 but then we would be using a list data structure for a very non list-like purpose which isn't ideal in my books.
Any ideas would be appreciated.