Syntax error with ternary operator

牧云@^-^@ 提交于 2019-12-02 02:39:31

Ternary operation in python using for expression, not statements. Expression is something that has value.

Example:

result = foo() if condition else (2 + 4)
#        ^^^^^                   ^^^^^^^
#      expression               expression

For statements (code blocks such as continue, for, etc) use if:

if condition:
     ...do something...
else:
     ...do something else...

What you want to do:

expanded = set()

while not someExpression:
    if currentState not in expanded: # you use set, so this condition is not really need
         expanded.add(currentState)
         # some code here
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!