Created
December 25, 2019 18:40
-
-
Save chrisjsimpson/a8c2b31c0818a46cc629541f6d105b8f to your computer and use it in GitHub Desktop.
Pack of cards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
import random | |
#Order of importance | |
suit = ['ace', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'jack', 'queen', 'king'] | |
def build_pack(): | |
''' Builds and returns a pack of sorted cards''' | |
cards = [] # Empty list of cards to be built | |
# Build hearts | |
for i,value in enumerate(suit, 1): | |
cards.append({ | |
'suit': 'heart', | |
'number': i, | |
'color' : 'red' | |
}) | |
# Build diamonds | |
for i,value in enumerate(suit, 1): | |
cards.append({ | |
'suit': 'diamond', | |
'number': i, | |
'color' : 'red' | |
}) | |
# Build clubs | |
for i,value in enumerate(suit, 1): | |
cards.append({ | |
'suit': 'club', | |
'number': i, | |
'color' : 'black' | |
}) | |
# Build spades | |
for i,value in enumerate(suit, 1): | |
cards.append({ | |
'suit': 'spade', | |
'number': i, | |
'color' : 'black' | |
}) | |
return cards | |
cards = build_pack() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pick a random card:
random.choice(cards)
Shuffle pack:
random.shuffle(cards)
Unshufflepack
cards = build_pack()