Йордан обнови решението на 26.03.2014 16:24 (преди над 10 години)
+from collections import OrderedDict
+
+
+CARDS_RANKS_AND_SYMBOLS = [('King', 'K'), ('Queen', 'Q'), ('Jack' , 'J'),
+ ('Ten', '10'), ('Nine', '9'), ('Eight', '8'), ('Seven', '7'),
+ ('Six', '6'), ('Five', '5'), ('Four' , '4'), ('Tree' , '3'),
+ ('Two', '2'), ('Ace' , 'A')]
+CARD_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+class Rank:
+ symbol = None
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+ color = None
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+RANKS = OrderedDict([(name, type(name, (Rank,), {'symbol': rank}))
+ for name, rank in CARDS_RANKS_AND_SYMBOLS])
+SUITS = OrderedDict([(color, type(color, (Rank,), {'color': color}))
+ for color in CARD_SUITS])
+
+class Card():
+
+ def __init__(self, card_rank, card_suit):
+ object.__setattr__(self, 'rank', card_rank())
+ object.__setattr__(self, 'suit', card_suit())
+
+ def __setattr__(self, *attr):
+ raise AttributeError("can't set attribute")
+
+ def __str__(self):
+ return ' of '.join([str(self.rank), str(self.suit)])
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+class CardCollection(list):
+ draw = list.pop
+
+ def draw_from_top(self):
+ return self.pop()
+
+ def draw_from_bottom(self):
+ return self.pop(0)
+
+ def top_card(self):
+ return self[-1]
+
+ def bottom_card(self):
+ return self[0]
+
+ def add(self, card):
+ self.append(card)
+
+
+def StandardDeck():
+ cards = [Card(rank, suit) for suit in SUITS.values()
+ for rank in RANKS.values()]
+ return CardCollection(cards)
+
+def BeloteDeck():
+ rank_classes = RANKS.values()
+ ranks_in_deck = rank_classes[:7]
+ ranks_in_deck.append(rank_classes[-1])
+ cards = [Card(rank, suit) for suit in SUITS.values()
+ for rank in ranks_in_deck]
+ return CardCollection(cards)
+
+def SixtySixDeck():
+ rank_classes = RANKS.values()
+ ranks_in_deck = rank_classes[:9]
+ ranks_in_deck.append(rank_classes[-1])
+ cards = [Card(rank, suit) for suit in SUITS.values()
+ for rank in ranks_in_deck]
+ return CardCollection(cards)