A function is overwitting a variable which is given it as an argument. Why?
What is this whole code supposed to do:
- create a list (main deck) of objects representing cards
- create an empty list for storage od the ids of cards already drawn from the main deck
- choose randomly 5 cards from the main deck and add them to the list (player's deck)
- return temp list of ints (ids of cards in the main deck) to a variable
add items from the temp list to the main list
import random from common import cards deck = cards.deck() # creates a list of 52 class objects representing cards def main(): used_cards_ids = [] # this one is being overwritten in the next step, according to the debugger players_deck, temp_used_cards_ids = generate_players_deck(used_cards_ids) # this is the "next step" used_cards_ids.extend(temp_used_cards_ids) # adds id of the cards which were drawn from the main deck print(used_cards_ids) # prints a double list of cards ids (i.e 1, 2, 3, 4, 5, 1, 2, 3, 4, 5) def generate_players_deck(temp_used_cards_ids): players_deck = [] counter = 0 while counter < 5: # until 5 cards were drawn cards_id = random.randint(0, 51) # chooses a random card if cards_id not in temp_used_cards_ids: # checks if the card with the same id weren't previously drawn counter += 1 temp_used_cards_ids.append(cards_id) # adds card's id to the list of drawn cards players_deck.append(deck[cards_id]) # adds card to the player's deck else: continue return players_deck, temp_used_cards_ids # returns player's deck (list of cards objects) and list of ids of the drawn cards main()