三个目录里的同名命令
运行下面这段程序,填写它打印出来的结果。
def first_hit(dirs, want, table, ok=None):
"""一串目录从左到右找 want;ok 决定「怎样才算命中」"""
for d in dirs:
entry = table.get((d, want))
if entry is None:
continue
if ok is None or ok(entry):
return d
return ""
TOOLS = {
("a", "tool"): {"能跑": False, "回答": "A"},
("b", "tool"): {"能跑": True, "回答": "B"},
("c", "tool"): {"能跑": True, "回答": "C"},
}
ABC = ["a", "b", "c"]
d = first_hit(ABC, "tool", TOOLS, lambda e: e["能跑"])
print(d + "/" + TOOLS[(d, "tool")]["回答"] + "/" + str(len(ABC)))
全部评论