I need to write these four if
s in Python. Notice what it does, is changing between four possible states in a loop: 1,0 -> 0,1 -> -1,0 -> 0,-1
and back to first.
if [dx, dy] == [1,0]:
dx, dy = 0, 1
if [dx, dy] == 0, 1:
dx, dy = -1, 0
if [dx, dy] == [-1, 0]
dx, dy = 0, -1
if [dx, dy] == [0, -1]:
dx, dy = 1, 0
Can anyone suggest me a better/nicer way to write this?
question from:
https://stackoverflow.com/questions/9104770/is-there-a-way-to-write-these-ifs-nicer 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…