Using Wikipedia's standard card deck definition I used two character string per card, with the first character being the rank of the card (2-10,JQKA) and the second being the suit.
So we end up with a list of 52 two character strings:
In [3]:
deck = [rank + suit for rank in '23456789TJQKA' for suit in 'SHDC']
print(deck)
Now to shuffle and deal cards from the deck:
In [40]:
import random
def deal(numhands=1, n=5, deck=[r+s for r in '23456789TJQKA' for s in 'SHDC']):
"""takes in numhands, and optionaly a deck, shuffles and returns a list of numhands hands"""
assert numhands*n <= len(deck), "you're trying to deal more cards then are in the deck"
random.shuffle(deck)
return [deck[i*n:n*(i+1)] for i in range(numhands)]
deal(3)
Out[40]:
In [ ]: