Part of a script that I am building requires me to map a user input to a list (possible inputs) which is then associated to a key (the result) in a dictionary. I have already manage to obtain the result but I want to know is there a better way that I can go about this?
user_input = "bought"
output = None
input_mapping = {"buy": ["bought", "buys", "purchased"],
"sell": ["sold", "sells", "sale"]}
for key, values in input_mapping.items():
if user_input in values:
output = key
print(output)
input / output:
user_input = "sale"
>>> sell
user_input = "bought"
>>> buy
Many thanks!