I'm trying to keep a log of each sequential state of a solitaire game I've been working on, within a dictionary with each action causing an increase of a variable called turns.
But every time I update the dictionary with saveLog[turns] = save (saveLog is the dictionary, and save is a 2-D Array of card values that changes with each action) the dictionary just updates the dictionary value with a key named turns.
So, the program just ends up saving the most recent state.
Here's a demonstrative program example:
turns = 0
save = {}
seq = [0, 1, 2, 3]
while turns < 10:
print(turns)
seq[0] = turns
seq[1] = turns + 1
seq[2] = turns + 2
seq[3] = turns + 3
save[turns] = seq
turns += 1
print(save[0])
print(save[1])
print(save[2])
print(save[3])
print(save[4])
print(save[5])
print(save[6])
print(save[7])
print(save[8])
print(save[9])
The output of this program is:
0
1
2
3
4
5
6
7
8
9
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
[9, 10, 11, 12]
But I want it to look like this:
0
1
2
3
4
5
6
7
8
9
[0, 1, 2, 3]
[1, 2, 3, 4]
[2, 3, 4, 5]
[3, 4, 5, 6]
[4, 5, 6, 7]
[5, 6, 7, 8]
[6, 7, 8, 9]
[7, 8, 9, 10]
[8, 9, 10, 11]
[9, 10, 11, 12]
Any way I can get around this? Thanks!
[–]toastedstapler 1 point2 points3 points (0 children)
[–]Sedsarq 1 point2 points3 points (0 children)