import random
class player():
def __init__(self, deck):
self.deck = deck
self.hand = []
self.results = []
def draw(self,draws):
for counter in range(0, draws, 1):
card = random.randrange(0, len(self.deck), 1)
self.hand.append(self.deck[card])
del self.deck[card]
def return_hand(self):
for returncounter in range(0, len(self.hand), 1):
self.deck.append(self.hand[returncounter])
for returncounter in range(0, len(self.hand), 1):
del self.hand[0]
def simple_function(self):
for counter in range(0, 3, 1):
print("Loop", counter)
self.draw(3)
print("Hand", simple_cards.hand)
self.results.extend(self.hand)
print("Results before return", simple_cards.results)
self.return_hand()
print("Results after return", simple_cards.results)
print("")
simple_cards = player(["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"])
simple_cards.simple_function()
print("Results after function", simple_cards.results)
An Example result from this code would be
Loop 0
Hand ['B3', 'B2', 'C3']
Results before return ['B3', 'B2', 'C3']
Results after return ['B3', 'B2', 'C3']
Loop 1
Hand ['C2', 'B3', 'A1']
Results before return ['B3', 'B2', 'C3', 'C2', 'B3', 'A1']
Results after return ['B3', 'B2', 'C3', 'C2', 'B3', 'A1']
Loop 2
Hand ['C2', 'B2', 'C1']
Results before return ['B3', 'B2', 'C3', 'C2', 'B3', 'A1', 'C2', 'B2', 'C1']
Results after return ['B3', 'B2', 'C3', 'C2', 'B3', 'A1', 'C2', 'B2', 'C1']
Results after function ['B3', 'B2', 'C3', 'C2', 'B3', 'A1', 'C2', 'B2', 'C1']
How do I make the result 3 nested lists like [['B3', 'B2', 'C3'], ['C2', 'B3', 'A1'], ['C2', 'B2', 'C1']]
I feel like there is a pretty fundamental thing I'm not understanding here and that this question has certainly already been answered but I don't know how to frame the question better to find it by searching myself.
I tried append(self.hand) and extend([self.hand]) but both created more problems than they solved resulting in an example output of
Loop 0
Hand ['B3', 'A2', 'B2']
Results before return [['B3', 'A2', 'B2']]
Results after return [[]]
Loop 1
Hand ['B2', 'B3', 'C3']
Results before return [['B2', 'B3', 'C3'], ['B2', 'B3', 'C3']]
Results after return [[], []]
Loop 2
Hand ['C2', 'B3', 'A2']
Results before return [['C2', 'B3', 'A2'], ['C2', 'B3', 'A2'], ['C2', 'B3', 'A2']]
Results after return [[], [], []]
Results after function [[], [], []]
Thanks for any help.