While coding a simple command-line tictactoe game to learn Python (here's a link to the entire script on repl.it), I was not happy with my game_over function, since a lot of code is repeated:
Edit: fixed the code by putting the [deck_is_full] if last instead of first
Edit 2: changed the code back to original for clarity
def game_over(deck):
if deck_is_full(deck):
return deck_is_full(deck)
if three_in_line(deck, "X"):
return three_in_line(deck, "X")
if three_in_line(deck, "O"):
return three_in_line(deck, "O")
return False
Is there a pythonic, repetition-free way to code that? I have found this answer on SO, but it doesn't get rid of the repetition, just gets it into a one-liner.