← Back to challenges

Poker Deck

PythonHardarraysgamesloopssorting

Instructions

Create a function that generates a poker deck.

A poker deck contains 52 cards in total, 13 cards for each of the four suits ( diamonds, clubs, hearts and spades) ranked 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A.

Your function should return a list (deck) containing each card as a tuple in the following format:

(rank, suit)

Where rank is a number from 2 to 14 (11, 12, 13 & 14 being J, Q, K & A respectively) and suit is a string with the first letter of the the card's suit ("d", "c", "h" & "s" for diamonds, clubs, hearts & spades respectively).

Examples

Five of hearts ➞ (5, "h")

Queen of Spades ➞ (12, "s")

Ace of Clubs ➞ (14, "c")

Notes

Extra points for shuffling the deck.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: RegEx XIX: Greedy vs Lazy Quantifiers