Is there a pythonic way to do the following? In a world with 2 words word1
and word2
, I want to return the opposite one, preferably with a one-liner
I'm currently doing the following and works but doesn't feel right:
def get_other_word(word):
if word == word1:
return word2
else:
return word1
I was thinking something like this but it throws an error:
def get_other_word(word):
word_choices = [word1, word2]
return word_choices.remove(word)[0]