import numpy as np
def data_verify(source):
rows = [x.strip().split(' ') for x in open(source)]
columns = zip(*rows)
blocks = np.array(rows).reshape((3,3,3,3)).transpose((0,2,1,3)).reshape((9,9))
#check iff, see further
return rows, columns, blocks
else:
return False
比如数独游戏:
^{pr2}$该函数收集所有相关数据,并在行的长度与列的长度相同的情况下返回相应的行、列和块(获得了一些其他函数来确定谜题是否合法)。我认为将第一行与所有列进行比较就足够了(反之亦然,也没有什么区别)。我如何才能创建一张支票,它的内容如下:
for i in range(len(rows)):
if len(row[0]) == len(column[i]):
#do something only if all of the lengths check out
使用^{} :
您可以在for循环中运行check并设置一个标志如果有任何不匹配,此示例将检查包含所有列的所有行:
相关问题 更多 >
编程相关推荐