Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taking the alternate value from tuple

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'
like image 941
desertSniper87 Avatar asked Feb 17 '26 23:02

desertSniper87


1 Answers

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']
like image 95
lmiguelvargasf Avatar answered Feb 20 '26 11:02

lmiguelvargasf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!