in the code, a function hash has been defined unnecessarily (there is a built in one that does the same - thanks to PhilDawes and DaveKirby for pointing this out)
code can be slightly cleaner using "from __future__ import nested_scopes" - thanks to PhilDawes for pointing this out)
code can be slightly cleaner by using "list comprehensions"