How to take the other(unmatched value) from tuple?
For example: I have val = 'y'
and t = ('y', 'n')
I want to return 'n' from the tuple. Something like
if val=='y':
return 'n'
else:
retun 'y'
You can use the following statement:
return t[0] if val == 'y' else t[1]
You can also index into a tuple:
return t[val == 'n']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With