I have a variable called CurrentLineup, which contains a set of 5 names as such
set(['Player 1', 'Player 2', 'Player 3', 'Player 4', 'Player 5'])
I have a loop of all of the events during a game, which includes other players' substitutions in and out of the game.
What I would like to do is create a list of all 5 man sets as CurrentLineup updates, so I initialized the following outside of the loop... take this code as an example.
Lineup_List = []
Lineup_List.append(Current_Lineup)
For i in game_events:
if "Enters Game" in i:
player = 'Player 6'
Current_Lineup.add(player)
if "Leaves Game" in i:
player2 = 'Player 4'
Current_Lineup.remove(player2)
if len(Current_Lineup) == 5:
Lineup_List.append(Current_Lineup)
My problem is that when I return Lineup_List after the loop, it has the final version of Current_Lineup a number of times.
If this loop ran twice, I would hope for Lineup_List to have the following result:
[set(['Player 1', 'Player 2', 'Player 3', 'Player 4', 'Player 5']),
set(['Player 1', 'Player 2', 'Player 3', 'Player 6', 'Player 5'])]
How do I retain the various values that CurrentLineup takes through the loop, in order of occurrence?
append(copy.deepcopy(myset))to store a copy, not the original