Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pack of cards
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()
@chrisjsimpson
Copy link
Author

chrisjsimpson commented Dec 25, 2019

Pick a random card:

random.choice(cards)

Shuffle pack:
random.shuffle(cards)

Unshufflepack
cards = build_pack()

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment