【发布时间】:2013-12-10 10:15:18
【问题描述】:
我严重睡眠不足,我需要帮助来重写这个小的 Python 逻辑
for _ in range(100):
if a:
continue
elif b:
continue
elif c and d:
continue
else:
e()
我想要类似的东西
if (some_exprt of a,b,c,d):
e()
我得到的是:
if not a and not b and (not c or not d):
e()
但我真的不知道这是否正确,对吗?
【问题讨论】:
-
你到底想做什么?
-
试着从“自下而上”的角度思考它。 "如果 a 或 b 或 c 和 d 都不为真,则执行 e()"
-
您可以使用De_Morgan's_laws 将您的答案转换为@Martijn 给出的答案
-
@InbarRose 循环和跳过不可行的迭代
-
简单的条件比复杂的条件好,
continue也很好(参见例如llvm.org/docs/…)。只需将elifs 替换为ifs 即可。
标签: python logic control-flow equivalence