Марио обнови решението на 26.03.2014 00:53 (преди над 10 години)
+from itertools import product
+
+
+def class_type_equality(self, other):
+ return isinstance(other, type(self))
+
+
+def stringify_class_name(self):
+ return type(self).__name__
+
+
+TYPE_BASED_METHODS = {'__eq__': class_type_equality,
+ '__str__': stringify_class_name}
+
+
+class Rank:
+ pass
+
+RANK_VALUES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+RANKS = {rank: type(rank, (Rank,), TYPE_BASED_METHODS) for rank in RANK_VALUES}
+
+
+class Suit:
+ pass
+
+SUIT_VALUES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+SUITS = {suit: type(suit, (Suit,), TYPE_BASED_METHODS) for suit in SUIT_VALUES}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __eq__(self, other):
+ if isinstance(other, type(self)):
+ return self.rank == other.rank and self.suit == other.suit
+ else:
+ return False
+
+ def __str__(self):
+ return str(self.rank) + ' of ' + str(self.suit)
+
+
+class CardCollection(list):
+ add = list.append
+ draw_from_top = list.pop
+ draw = list.pop
+ index = list.index
+
+ def top_card(self):
+ return self[-1]
+
+ def bottom_card(self):
+ return self[0]
+
+ def draw_from_bottom(self):
+ return self.pop(0)
+
+
+def pair_to_card(pair):
+ return Card(RANKS[pair[1]], SUITS[pair[0]])
+
+
+def deck_from_rank_strings(ranks):
+ collection = [pair_to_card(pair) for pair in product(SUIT_VALUES, ranks)]
+ return CardCollection(collection)
+
+
+def StandardDeck():
+ return deck_from_rank_strings(RANK_VALUES)
+
+
+def BelotteDeck():
+ return deck_from_rank_strings(RANK_VALUES[:7] + [RANK_VALUES[-1]])
+
+
+def SixtySixDeck():
+ return deck_from_rank_strings(RANK_VALUES[:5] + [RANK_VALUES[-1]])