MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __init__

Method __init__

project_euler/problem_054/sol1.py:105–134  ·  view source on GitHub ↗

Initialize hand. Hand should of type str and should contain only five cards each separated by a space. The cards should be of the following format: [card value][card suit] The first character is the value of the card: 2, 3, 4, 5, 6, 7, 8, 9,

(self, hand: str)

Source from the content-addressed store, hash-verified

103 )
104
105 def __init__(self, hand: str) -> None:
106 """
107 Initialize hand.
108 Hand should of type str and should contain only five cards each
109 separated by a space.
110
111 The cards should be of the following format:
112 [card value][card suit]
113
114 The first character is the value of the card:
115 2, 3, 4, 5, 6, 7, 8, 9, T(en), J(ack), Q(ueen), K(ing), A(ce)
116
117 The second character represents the suit:
118 S(pades), H(earts), D(iamonds), C(lubs)
119
120 For example: "6S 4C KC AS TH"
121 """
122 if not isinstance(hand, str):
123 msg = f"Hand should be of type 'str': {hand!r}"
124 raise TypeError(msg)
125 # split removes duplicate whitespaces so no need of strip
126 if len(hand.split(" ")) != 5:
127 msg = f"Hand should contain only 5 cards: {hand!r}"
128 raise ValueError(msg)
129 self._hand = hand
130 self._first_pair = 0
131 self._second_pair = 0
132 self._card_values, self._card_suit = self._internal_state()
133 self._hand_type = self._get_hand_type()
134 self._high_card = self._card_values[0]
135
136 @property
137 def hand(self):

Callers

nothing calls this directly

Calls 3

_internal_stateMethod · 0.95
_get_hand_typeMethod · 0.95
splitMethod · 0.80

Tested by

no test coverage detected