I will try to answer your question in stages, my internet service is kicking me out all too frequently as of late.
The first function of the card game uses a thing called list comprehension, an efficient way to create a list. Allow me to use php tags to add some color to the code ...
[php]def create_cards():
"""
create a list of 52 cards
suit: club=C, diamond=D, heart=H spade=S
rank: ace=A, 10=T, jack=J, queen=Q, king=K, numbers=2..9
ace of spade would be SA, 8 of heart would be H8 and so on ...
"""
return [ suit + rank for suit in "CDHS" for rank in "A23456789TJQK" ]
[/php]You can break down the list comprehension to the more traditional way to create a list ...
[php]# create a list of all card names using a list comprehension
card_list1 = [ suit + rank for suit in "CDHS" for rank in "A23456789TJQK" ]
# a list comprehension is a more efficient way to create a list than
# this traditional nested for loop way ...
card_list2 = []
for suit in "CDHS":
for rank in "A23456789TJQK":
# eg. append the concatination of 'C'+'A' = 'CA'
card_list2.append(suit+rank)
# to test print the first 13 items of each card list ...
print card_list1[:13] # ['CA', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'CT', 'CJ', 'CQ', 'CK']
print card_list2[:13] # ['CA', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'CT', 'CJ', 'CQ', 'CK']
[/php]You could use either way, but a list comprehension is simply faster. There is a discussion on list comprehension at:
http://www.daniweb.com/code/snippet454.html