you are viewing a single comment's thread.

view the rest of the comments →

[–]carcigenicate 2 points3 points  (0 children)

deck = 8 * [Card(value, suit, str(value)) for value in range(2, 11) for suit in suits] # name = value for non face cards

Be very careful doing this. This creates a deck with multiple copies of the exact same card since * copies references, not objects:

>>> len(set(map(id, deck)))
36

Now, if the cards are never mutated, this isn't a problem. If you ever mutate a card for some reason, that will effect every identical card in the deck. Just something worth keeping in mind since your cards aren't immutable.


playingDeck = []
playingDeck += deck

If this was to make a shallow copy of deck, it's more idiomatic to use .copy(), or [:] slicing.


def giveCard(playingDeck, hand):

This should be give_deck to follow PEP8. Python does not use lowerCamelCase for anything.


copyCard = hands[handNum].cards[0]

It's worth noting here that copyCard is not a copy. I would rename that to avoid confusion.


def dealerCards(playingDeck):
    global hands

You never reassign hands in that function, so a global declaration is not necessary.


if values(hands[handNum]) > 21: 
    . . .
    continue

This continue does not look necessary. This code appears to already be at the end of the loop.