我在想,如果有可能的if
语句嵌套在一个主一个像这样的内部优先级代码:循环,具有优先级/顺序
for blah:
if case1:
# takes highest priority and
# will execute first even if
# other cases are true
if case2:
# takes lower priority
if case3:
# takes lowest priority
我能找到的唯一的事情也许是一个优先级队列等作为heapq
,但我不完全理解如何工作,或者如果他们是相关的。
更专门为我的代码:
for x in list_of_lists: # x would be a list then containing multiple integers
if 1 in x and not (2 in x or 3 in x):
# basically just want to see if the list "x" = [1]
# takes highest priority and
# will execute first even if
# other cases are true
if 1 in x and (2 in x or 3 in x):
# checking to see if the list "x" contains a 1 and a 2, or a 1 and a 3
# takes lower priority
if something similar to the above:
# takes lowest priority
欢迎StackOverflow的这相当于
switch-case
声明!如果你有两个不同的问题,你应该将它们作为两个问题发布。 (我可以回答你的第二个问题,但请先将它们分开。) – jpmc26 2014-09-19 06:04:05要明确你的问题并不容易,但是对于你的第一个问题:你似乎在这里提出的概念是可行的。优先队列是完全不同的,与你的问题没有关系。阅读一些教程:https://docs.python.org/2/tutorial/controlflow.html – 2014-09-19 06:08:11
jpmc26,我会道歉,但它说我不能再过90分钟,任何机会,你可以私人消息我,然后我可以编辑它? – rawa 2014-09-19 06:12:43