I have a menu that will return ‘e’ unless the input is d or D.
I would like to do it without making another variable and doing it on one line
encrypt = 'd' if (raw_input("Encrypt or Decrypt a file(E/d):") == ('d' or 'D')) else 'e'
[Edit]
Ok here is a harder one
How can I do the same for this
file_text = 'a.txt' if (raw_input("File name(a.txt):")=='a.txt' else [What I typed in]
Use the
inoperator:Alternatively, you can just convert the input to lowercase and compare it to ‘d’:
Finally, if you want to ensure that they enter e or d, you can wrap it up in a while loop:
Edit: To answer your second question, you can use a lambda for it I guess?
Although, this is clearly a bit obtuse and too “clever” by half.