Created
January 27, 2024 18:54
-
-
Save sungiven/9243f6d82f8848eeb7ac4c04ac990bdf to your computer and use it in GitHub Desktop.
Cartesian product of card ranks & suits
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
#!/usr/bin/env python3 | |
card_ranks = ["A", "K", "Q"] | |
card_suits = ["♠", "♥", "♦", "♣"] | |
# cartesian product of cards, arranged by ranks | |
cards = [(rank, suit) for rank in card_ranks for suit in card_suits] | |
print(cards) | |
# cartesian product of cards, arranged by suits | |
cards = [(rank, suit) for suit in card_suits for rank in card_ranks] | |
print(cards) | |
""" | |
output: | |
[('A', '♠'), ('A', '♥'), ('A', '♦'), ('A', '♣'), ('K', '♠'), ('K', '♥'), ('K', '♦'), ('K', '♣'), ('Q', '♠'), ('Q', '♥'), ('Q', '♦'), ('Q', '♣')] | |
[('A', '♠'), ('K', '♠'), ('Q', '♠'), ('A', '♥'), ('K', '♥'), ('Q', '♥'), ('A', '♦'), ('K', '♦'), ('Q', '♦'), ('A', '♣'), ('K', '♣'), ('Q', '♣')] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment