Using a tertiary if and in for a Pythonic search on the fly

This doesn’t need a lot of explanation, but just one line below combining an inline if with the in operator packs an amazing amount of power in such a simple, short, easy to understand statement.  Its beautiful really.


# tertiary (inline) if
# use in to search a list on the fly
myword1, myword2 = "zebra", "carrot"
animals = ["bat", "dog", "zebra", "catfish", "fish"]
print(myword1 + ":", end=" ")
print("animal" if myword1 in animals else 'vegetable')
print(myword2 + ":", end=" ")
print("animal" if myword2 in animals else 'vegetable')
<p style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">

results will be:
zebra: animal
carrot: vegetable