"Darth Kaboda" <[email protected]> wrote
cb = [[[0, None]] * (n + 1)] * (m + 1)
cb[3][2][0] = 10
This last statement causes the every first element in the list to update.
Is this becuase this method of initializing a list is just a copy
Yes exactly.
To get around this I'm now doing the folowing:
cb = [[[0,None] for x in range(n+1)] for y in range(m+1)]
Yes, that's what list comprehensions are for, to create lists.
Is this an acceptable practice?
Absolutely. It is one of the most common uses for comprehensions.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor