In my code, I have the nested list gamelist
, defined as
gamelist = [['3'], ['2'], ['1']]
The purpose of the program is to treat the internal lists as stacks, appending smaller elements to stacks containing larger elements or empty stacks, sweeping up and down the list and not repeating moves. Theoretically this game should go:
[['3'], ['2'], ['1']]
[['3'], ['2', '1'], []]
[['3', '1'], ['2'], []]
[['3', '1'], [], ['2']]
And so on, until the list is sorted from smallest to largest.
In order to check the current move against previous moves, I created pastmoves
, which has a copy of gamelist
appended to it after each move.
pastmoves.append(gamelist[:])
So pastmoves
should read
[[['3'], ['2'], ['1']]]
[[['3'], ['2'], ['1'], [['3'], ['2', '1'], []]]
and so on after each consecutive move.
My issue is that while gamelist is being copied, the lists nested inside it are not, and pastmoves
looks like this after two moves:
[[['3'], ['2', '1'], []], [['3'], ['2', '1'], []]]
I'd like to make it so that all of the bottom-level values are also copies and remain static as gamelist
changes. How can I achieve that?