I am trying to create card game simulations to improve my programming skills a bit, and i am stuck with the following problem:
I have the cards in a big list, and i use the next function to pick a card and remove it from the deck.
cards= [........(big list of cards here in string format).......]
def Pickacard(x):
rand=random.randint(0,len(x)-1)
t=int(x[rand])
del(x[rand])
return t
When i use the following iteration, the deck isnt beeing renewed. Instead every time a card gets picked, the deck remains 1 item shorter, despite the fact that in every loop, i have set "test=cards" so that it sets the list back to the original.
for i in range(200):
test=cards
Pickacard(test)
print(test)
Deck had 208 cards, if the deck was renewed then (print test) would give me a list of 207 cards. Instead i get a list of 8 cards. I though this would only happen if ....test=cards.... was outside of the loop.