Recursion Help - Peter Norvig's Sudoku Exercise
Hi I am currently going through Peter Norvig's sudoku solution (http://norvig.com/sudoku.html). However, I have a bit of confusion with the block code below: def assign(values, s,
Solution 1:
Python dicts are mutable, meaning that their value can be changed.
This example is showing an anti-pattern: You shouldn't both mutate an argument and return it. An example is all the methods that change a list (append, pop, etc.) don't return the original list.
The eliminate function gets the same dict as in the assign function, and any changes in the assign function are reflected in the elimate function.
Here is an example:
def update(dict_, key, value):
dict_[key] = value
d = {
1: 2,
3: 4
}
update(d, 1, 100)
update(d, 3, 100)
print(d[1] + d[3]) # 200
Post a Comment for "Recursion Help - Peter Norvig's Sudoku Exercise"