Since full unicode is the current range of the default string type (str), I find my initial explorations of strings often swerve into chess pieces, playing cards, emoji.
Speaking of playing cards: I'm surprised to discover an unfamiliar face card this late in life. Unicode has a "Knight" (letter C) in all four suits. I'm so used to Bicycle decks with suits of 13.
I chop out all the Knights using slice notation in the Notebook linked below.The playing card motif is especially apropos around Python given the logo has th
at face card symmetry
, if you know what I mean.
I believe Luciano Ramahlo does playing cards quite a bit, along with little flag GIFs (served by nginx), which I think these days could be emoji.If not bothering with Unicode, then why not just:
from random import shuffle
suits = "Hearts Clubs Spades Diamonds".split() # chop me up
royals = "Ace Jack Queen King".split() # could Ace be a she? Sure!
normals = [str(i) for i in range(2, 11)] # starts at 1, stops at 10
deck = [ ] # I'm an empty list
for s in suits: # outer loop
for n in [royals[0]] + normals + royals[1:]: # Ace, normals, rest
card = (n, s) # (suit, face value)
deck.append(card)
deck += ["Joker", "Joker"] # need these too!
print("Fresh from box:\n", deck)
shuffle(deck)
print("Shuffled:\n", deck)
But then we'd probably want instances of the Deck class no? Self shuffling.
Besides, I think bothering with Unicode is worth the effort.
Lets not lazily pretend we still live in the days of ASCII.