Problem with list of dicts and copying
gagsl-py2 at yahoo.com.ar
Thu Jul 9 04:19:37 EDT 2009
En Wed, 08 Jul 2009 14:09:43 -0300, Cameron Pulsford
<cameron.pulsford at gmail.com> escribió:
> I'm representing the board as a dictionary, where the keys are
> (x, y) positions, and the values are candidates. So my program goes along
> picking numbers from the list of candidates and then propagating the
> constraints. [...]Basically my boards list should be copies of good
> boards, and when I need to
> refresh the current board, I want to pull off a copy of the correct one.
> [...] this isn't happening. I am always modifying the same board.
You have a dictionary whose values are lists, ok? The copy() method
doesn't make a copy of those lists - only of the dictionary itself. Try
using the deepcopy function in the copy module:
More information about the Python-list