Why this is happening? I don't really understand:
>>> P = [ [()]*3 ]*3
>>> P
[[(), (), ()], [(), (), ()], [(), (), ()]]
>>> P[0][0]=1
>>> P
[[1, (), ()], [1, (), ()], [1, (), ()]]
You've made 3 references to the same list.
>>> a = b = []
>>> a.append(42)
>>> b
[42]
You want to do this:
P = [[()] * 3 for x in range(3)]