这是该函数(source):
def search(values):
"Using depth-first search and propagation, try all possible values."
if values is False:
return False ## Failed earlier
if all( len( values[s]) == 1 for s in squares):
return values ## Solved!
## Chose the unfilled square s with the fewest possibilities
_,s = min( (len( values[s]), s)
for s in squares
if len(values[s]) > 1
)
return some( search( assign( values.copy(), s, d))
for d in values[s]
)
(为方便起见,我添加了一些空格,CR和制表符;对Norvig博士表示歉意。)
在评论的正下方,有一行以“ _,s” 开头。那似乎是len(values[s]),s最小值为的解压元组()s。Norvig博士是否使用“ _”作为变量名只是为了表明它是“无关”结果,还是其他情况?有时_建议使用“ ”作为变量名吗?在交互模式下,“ _”保留上一个操作的答案;非交互式代码中有类似的功能吗?
更新资料
感谢您的好答案。我猜答案是Alex Martelli的“增值”;他指出,“ _,vbl_of_interest”惯用语通常是DSU惯用语的副作用,而DSU惯用语本身已被不必要。
ITMISS
湖上湖
相关分类