[Tutor] Still having trouble with my game of life algorithm
malaclypse2 at gmail.com
Sat May 26 02:07:53 CEST 2007
On 5/25/07, Matt Smith <matt at mattanddawn.orangehome.co.uk> wrote:
> def update_matrix(matrix):
> matrix_updated = matrix
That line assigns the name matrix_updated to the same list-of-lists as
matrix. Since lists are mutable objects, changing matrix_updated is
also changing matrix. What you need is to bind matrix_updated to a
new copy of matrix instead.
At the top of your code add:
from copy import deepcopy
and replace the first line of update_matrix() with:
matrix_updated = deepcopy(matrix)
After making that change, your code appears to run beautifully!
More information about the Tutor