Question: Every time I run this command, I can't get through all of the cards without having this error; `IndexError`: list index out of range.

```
import random

cards = ['2', '2', '2', '2', '3', '3', '3', '3', '4', '4', '4', '4', '5', '5', '5', '5', '6', '6', '6', '6', '7', '7', '7', '7', '8', '8', '8', '8', '9', '9', '9', '9', '10', ',10', '10', '10', 'J', 'J', 'J', 'J', 'Q', 'Q', 'Q', 'Q', 'K', 'K', 'K', 'K', 'A', 'A', 'A', 'A']

randomness = 51

while True:

    cardIndex = random.randint(0, randomness)
    del cards[cardIndex]
    randomness = randomness -1
    print(cards[cardIndex])

```

Answer: 
Print `cards[cardIndex]` *before* deleting by that index:

```
while cards: # Because we need to stop somewhere
    cardIndex = random.randint(0, randomness)
    print(cards[cardIndex])
    del cards[cardIndex]
    randomness = randomness -1

```

And you don't need `randomness` at all:

```
while cards:
    cardIndex = random.randrange(len(cards))
    print(cards[cardIndex])
    del cards[cardIndex]

```

---

You'd do that using either [`random.sample`](https://docs.python.org/3/library/random.html#random.sample):

```
for c in random.sample(cards, len(cards)):
    print(c)

```

or [`random.shuffle`](https://docs.python.org/3/library/random.html#random.shuffle) (which will modify the `cards` list):

```
random.shuffle(cards)
for c in cards:
    print(c)

```
```
while cards:
    idx = random.randint(0, len(cards) - 1)
    print(cards[idx])
    del cards[idx]

```