When it is required to shuffle a deck of cards using Python, the 'itertools' and the 'random' packages need to be used. Random library has a method named 'shuffle' that can be used to mix up and show the data.
Below is a demonstration for the same −
import itertools, random my_deck = list(itertools.product(range(1,11),['Spade','Heart','Diamond','Club'])) print("The cards are being shuffled") random.shuffle(my_deck) print("Cards are drawn at random") print("They are : ") for i in range(5): print(my_deck[i], "of", my_deck[i])
The cards are being shuffled Cards are drawn at random They are : 1 of Diamond 5 of Diamond 4 of Club 2 of Spade 4 of Heart