Given this set and an input GET parameter that indicates a chosen fruit
fruit = {'apple', 'banana', 'orange', 'pear'}
Is there a compact way to do this in one line in python?
chosen = request_obj.get('fruit', '')
if chosen not in fruit:
chosen = ''
Here’s another way:
Honestly, though, I think what you have is more readable and the better choice.