I would use itertools.product
to get the possible value of cards into a list, then shuffle that and take of 5 cards at a time for each player you want.
from itertools import product
from random import shuffle
suits = ["C","D","H","S"]
ranks = ["2","3","4","5","4","6","7","8","9","J","Q","K","A"]
cards = list(r + s for r, s in product(ranks, suits))
shuffle(cards)
print cards[:5], cards[5:10] # change this into a suitable for loop to slice
['4D', 'KC', '5H', '9H', '7D'] ['2D', '4S', '8D', '8S', '4C']
And you could use the following recipe from itertools
to just get the next 5 cards depending on how many players.
def grouper(n, iterable, fillvalue=None):
from itertools import izip_longest
"Collect data into fixed-length chunks or blocks"
# grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx
args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args)
hand = grouper(5, cards)
for i in xrange(5): # deal for 5 players...
print next(hand) # each time we call this, we get another 5 cards
('4D', 'KC', '5H', '9H', '7D')
('2D', '4S', '8D', '8S', '4C')
('AD', '2H', '4S', 'KS', '9S')
('6H', 'AH', '4H', '5S', 'KD')
('6S', 'QD', '3C', 'QC', '8H')