def init_valid(self):
# Fill out dictionary V such that V[(r,c)], where (r,c) are the coordinates of a cell, contains the set of integers that can be
# written in cell (r,c) without breaking any of the rules
# If a number has already been written in cell (r,c), then V[(r,c)] should contain the empty set
self.V = {(i,j):{0,1,2,3,4,5,6,7,8,9} - set(self.S[value[0]][value[1]] for value in self.N[(i,j)]) for i in range(9) for j in range(9)}
大家好,我目前正在做一個在 python 上構建 Sudoku Solver 的專案,我只是想了解語法以及這行 self.V 的作用,它填寫了可以用特定語言撰寫的數字坐標對應于給出數獨規則的位置,如果寫的數字是從 V 字典中取出的行、列或 3 x 3 部分,任何見解都將不勝感激
uj5u.com熱心網友回復:
您的代碼是以下內容的超級緊湊版本:
self.V = {}
for i in range(9):
for j in range(9):
my_set = set()
for value in self.N(i, j):
my_set.add(self.S[value[0]][value[1]])
self.V[(i, j)] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - my_set
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/521666.html
標籤:Python字典数独
上一篇:這是什么資料結構?-什么語言?
