Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- from random import choice
- Card = collections.namedtuple('Card',['rank', 'suit'])
- class FrenchDeck:
- ranks = [str(n) for n in range (2, 11)] + list ('JQKA')
- suits = 'spades diamonds clubs hearts'.split()
- suits_values = dict(spades=3, hearts=2, diamonds=1, clubs=0)
- 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]
- >>> beer_dark = Card('7', 'diamonds')
- >>> beer_card
- Card(rank='7', suit='diamonds')
- >>> deck = FrenchDeck()
- >>> len(deck)
- 52
Add Comment
Please, Sign In to add comment