In some part of my Python program I have a val variable that can be 1 or 0. If it\'s 1 I must change to 0, if it\'s 0 I must change to 1.
How do you do it in a Pytho
I have swapped 0s and 1s in a list.
Here's my list:
list1 = [1,0,0,1,0] list1 = [i^1 for i in list1] #xor each element is the list print(list1)
So the outcome is: [0,1,1,0,1]