Is there a more elegant way to toggle between two strings or integers in Python 3?
x={"A":"B", "B":"A"}[x]
The values can be non-boolean, like string or integer. Let's suppose that we want to toggle between "A" and "B" and the variable name is x.
In other words: if x = "A"
then the result should be x = "B"
and if x = "B"
then the result should be x = "A"
.
input:
x="B"
output:
x="A"