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

Function parse_moves

matrix/matrix_based_game.py:105–125  ·  view source on GitHub ↗

>>> parse_moves("0 1, 1 1") [(0, 1), (1, 1)] >>> parse_moves("0 1, 1 1, 2") Traceback (most recent call last): ... ValueError: Each move must have exactly two numbers. >>> parse_moves("0 1, 1 1, 2 4 5 6") Traceback (most recent call last): ... ValueEr

(input_str: str)

Source from the content-addressed store, hash-verified

103
104
105def parse_moves(input_str: str) -> list[tuple[int, int]]:
106 """
107 >>> parse_moves("0 1, 1 1")
108 [(0, 1), (1, 1)]
109 >>> parse_moves("0 1, 1 1, 2")
110 Traceback (most recent call last):
111 ...
112 ValueError: Each move must have exactly two numbers.
113 >>> parse_moves("0 1, 1 1, 2 4 5 6")
114 Traceback (most recent call last):
115 ...
116 ValueError: Each move must have exactly two numbers.
117 """
118 moves = []
119 for pair in input_str.split(","):
120 parts = pair.strip().split()
121 if len(parts) != 2:
122 raise ValueError("Each move must have exactly two numbers.")
123 x, y = map(int, parts)
124 moves.append((x, y))
125 return moves
126
127
128def find_repeat(

Callers 1

Calls 2

splitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected