Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
zip, list comp, try next solution in Clear category for Xs and Os Referee by r_tchaik
from typing import List
def checkio(game_result: List[str]) -> str:
lines = game_result + [''.join(col) for col in zip(*game_result)] + \
[''.join(game[idx][idx] for idx in range(3)) for game in (game_result, game_result[::-1])]
try:
return next(item[0] for item in lines if len(set(item)) == 1 and item[0] != '.')
except StopIteration:
return 'D'
if __name__ == '__main__':
print("Example:")
print(checkio(["X.O",
"XX.",
"XOO"]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
assert checkio([
"O.X",
"XX.",
"XOO"]) == "X", "Xs wins again"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
July 17, 2020
Comments: