You want random.shuffle()
:
>>> import random
>>> l = [1, 2, 3, 4, 5]
>>> random.shuffle(l)
>>> l
[2, 1, 5, 3, 4]
Since it seems you can't use random.shuffle
, perhaps your teacher wanted you to use random.randint()
to get a random number between 1-13, then a random suit (hearts, clubs, diamonds, spades), and form a list like that. Keep in mind you'll need to check if the card already exists in the list.
Try have an attempt first, but if you can't do it, then here's the solution. I strongly recommend you have a go first using the approach I just mentioned above.
l = []
while len(l) < 52:
number = random.randint(1, 13)
suit = random.choice(['hearts', 'clubs', 'diamonds', 'spades'])
card = (number, suit)
if card not in l:
l.append(card)