I'm making a card game in pygame and I'm storing the cards used in a list that receives the elements from a for loop which iterates through the files stores. I want to prevent the same card from being drawn twice so I thought that if the card has been drawn, remove it as an option from the list to prevent it. But the list removes method gives me an error saying that the element is not in the cards_list, yet it is.
cards_list = []
cards_tpye_1 = ['D', 'H', 'C', 'S']
cards_tpye_2 = ['Q', 'K', 'A', 'J']
for card in cards_tpye_1:
for x in range(2, 11):
img = pygame.image.load(f'img\cards\{card}{x}.png')
img = pygame.transform.scale(img, (img.get_width() * 2, img.get_height() * 2))
cards_list.append(img)
for card in cards_tpye_2:
for suit in cards_tpye_1:
img = pygame.image.load(f'img\cards\{card}{suit}.png')
img = pygame.transform.scale(img, (img.get_width() * 2, img.get_height() * 2))
cards_list.append(img)
dealer_card_1 = random.choice(cards_list)
card_1 = random.choice(cards_list)
card_2 = random.choice(cards_list)
cards_dealt = False
dealer_cards_list = []
player_cards_list = []
if cards_dealt is True:
screen.blit(dealer_card_1, (width//3, 50))
dealer_cards_list.append(dealer_card_1)
screen.blit(card_1, (width//3, height//2))
screen.blit(card_2, (width//3 + 140, height//2))
player_cards_list.append(card_1)
player_cards_list.append(card_2)
cards_list.remove(card_1)
cards_list.remove(card_2)
cards_list.remove(dealer_card_1)
ValueError: list.remove(x): x not in list
I tried creating a new list of the dealt cards but it gives the same error when I attempt to remove the cards.