fruit = {'apple', 'banana', 'orange', 'pear'}
d = {'fruit': 'apple'}
chosen = '' if d.get('fruit', '') not in fruit else d.get('fruit', '')
chosen
d['fruit'] = 'watermellon'
chosen = '' if d.get('fruit', '') not in fruit else d.get('fruit', '')
chosen
Testing whether a value is in a set and assigning variable