Георги обнови решението на 26.03.2014 14:20 (преди над 10 години)
+RANK_SYMBOLS = {'King': 'K', 'Queen': 'Q', 'Jack': 'J',
+ 'Ten': '10', 'Nine': '9', 'Eight': '8',
+ 'Seven': '7', 'Six': '6', 'Five': '5',
+ 'Four': '4', 'Three': '3', 'Two': '2',
+ 'Ace': 'A'}
+
+RANK_ORDER = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two',
+ 'Ace']
+
+SUIT_COLORS = {'Diamonds': 'red', 'Hearts': 'red',
+ 'Spades': 'black', 'Clubs': 'black'}
+
+SUIT_ORDER = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+class ComparableDisplayable:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return self.__class__.__name__ == other.__class__.__name__
+
+
+class Rank(ComparableDisplayable):
+ pass
+
+
+class Suit(ComparableDisplayable):
+ pass
+
+RANKS = {rank: type(rank, (Rank,), {"symbol": symbol})
+ for (rank, symbol) in RANK_SYMBOLS.items()}
+
+SUITS = {suit: type(suit, (Suit,), {"color": color})
+ for (suit, color) in SUIT_COLORS.items()}
+
+
+class Card:
+ __RANK_ORDER__ = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two',
+ 'Ace']
+
+ __SUIT_ORDER__ = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+ def __init__(self, rank, suit):
+ self._rank, self._suit = rank(), suit()
+
+ def __eq__(self, other):
+ return self._rank == other._rank and self._suit == other._suit
+
+ def __str__(self):
+ return '%s of %s' % (str(self._rank), str(self._suit))
+
+ def __repr__(self):
+ return str(self)
+
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.__collection = list(collection)
+
+ def __len__(self):
+ return len(self.__collection)
+
+ def __getitem__(self, key):
+ return self.__collection[key]
+
+ def __iter__(self):
+ for card in self.__collection:
+ yield card
+
+ def __repr__(self):
+ return str([str(card) for card in self.__collection])
+
+ def add(self, card):
+ self.__collection.append(card)
+
+ def draw(self, index):
+ return self.__collection.pop(index)
+
+ def draw_from_top(self):
+ return self.__collection.pop()
+
+ def draw_from_bottom(self):
+ return self.__collection.pop(0)
+
+ def top_card(self):
+ return self.__collection[-1]
+
+ def bottom_card(self):
+ return self.__collection[0]
+
+ def index(self, card):
+ return self.__collection.index(card)
+
+
+def StandardDeck():
+ return CardCollection([Card(RANKS[rank], SUITS[suit])
+ for suit in SUIT_ORDER
+ for rank in RANK_ORDER])
+
+def BeloteDeck():
+ return CardCollection([Card(RANKS[rank], SUITS[suit])
+ for suit in SUIT_ORDER
+ for rank in RANK_ORDER[:7] + RANK_ORDER[-1::]])
+
+def SixtySixDeck():
+ return CardCollection([Card(RANKS[rank], SUITS[suit])
+ for suit in SUIT_ORDER
+ for rank in RANK_ORDER[:5] + RANK_ORDER[-1::]])
Предполагам глобалните константи трябва да "живеят" в някой клас .