list index out of range

Mike Kent mrmakent at cox.net
Tue May 13 15:02:13 EDT 2008


On May 13, 2:39 pm, Georgy Panterov <gpante... at yahoo.com> wrote:
>
> def deal_hand(deck):
>     HAND=[]
>     for _ in range(2):
>         i=random.randint(0,len(deck)) #produces a random card from the deck
          ^ Here i can be from 0 thru (the number of cards in the
deck).

>         HAND.append(deck[i]) # appends the card to the players' hand list
                           ^ Here you index into the deck to get a
card.  The legal indexes are 0 thru (number of cards in the deck - 1)
                             What happens if i is (the number of cards
in the deck)?

>         deck.remove(deck[i]) #removes the card from the deck
>     return HAND
>



More information about the Python-list mailing list