forked from jwasham/practice-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.py
More file actions
35 lines (25 loc) · 780 Bytes
/
deck.py
File metadata and controls
35 lines (25 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import collections
import random
Card = collections.namedtuple('Card', ['rank', 'suit'])
class Deck:
ranks = [str(i) for i in range(2, 11)] + list('JKQA')
suits = 'spades diamonds clubs hearts'.split()
def __init__(self):
self._cards = [Card(rank, suit) for suit in self.suits
for rank in self.ranks]
def __len__(self):
return len(self._cards)
def __getitem__(self, position):
return self._cards[position]
def __repr__(self):
return 'Deck()'
def main():
deck = Deck()
# print(len(deck))
for __ in range(5):
print(random.choice(deck))
# print(deck[12::13])
# for card in reversed(deck):
# print(card)
if __name__ == "__main__":
main()