Created
August 29, 2015 12:16
-
-
Save sivabudh/cf27226dfe40d9ec0dcf to your computer and use it in GitHub Desktop.
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
__author__ = 'Pac' | |
import collections | |
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() | |
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_card = Card('7', 'diamonds') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment