I am trying to make a deck of playing cards,where each is a tuple. For example, the card 'Ace of Hearts' with value of 11 would be (‘A’, ‘♥’, 11)
.
How can I generate the entire deck without using classes and save it in a list?
Using static definitions for the suits, cards, and values, you can do the following to get a list of cards using a list comprehension - the deck list then contains tuples representing cards. You may want to change how the values list is defined according to your requirements.
suits = ['♠', '♥', '♦', '♣']
cards = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
values = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
deck = [(c, s, v) for c, v in zip(cards, values) for s in suits]