[python] complex if statement in python