Skip to content

Instantly share code, notes, and snippets.

@chrisjsimpson
Created December 25, 2019 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisjsimpson/a8c2b31c0818a46cc629541f6d105b8f to your computer and use it in GitHub Desktop.
Save chrisjsimpson/a8c2b31c0818a46cc629541f6d105b8f to your computer and use it in GitHub Desktop.
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

Pick a random card:

random.choice(cards)

Shuffle pack:
random.shuffle(cards)

Unshufflepack
cards = build_pack()

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