Python 检查特定列表项和其他列表项

Python 检查特定列表项和其他列表项,python,list,loops,tkinter,multidimensional-array,Python,List,Loops,Tkinter,Multidimensional Array,我正在做一个数独游戏,我需要能够检查输入的数字是否已经在行或列中存在冲突。现在,这正在更改所有种子值的背景。如何检查特定条目并查看它是否已在行或列中 #nums_list is a 2_d list of the Entry widget id tags #check_list are the 0's and digits of the seed values def check_conf(self): for r in range(0, self.height, 1):

我正在做一个数独游戏,我需要能够检查输入的数字是否已经在行或列中存在冲突。现在,这正在更改所有种子值的背景。如何检查特定条目并查看它是否已在行或列中

  #nums_list is a 2_d list of the Entry widget id tags
  #check_list are the 0's and digits of the seed values
  def check_conf(self):
    for r in range(0, self.height, 1):
        for c in range(0, self.width, 1):
            if self.nums_list[r][c].get().isdigit():
                if int(self.nums_list[r][c].get()) == int(self.check_list[r][c]):
                    self.nums_list[r][c].config(background = 'red')

完整的代码在

很高兴你找到了它

我将冒着被否决的风险回答这一评论:如果您这样做,您可以使代码更具可读性:

#nums_list is a 2_d list of the Entry widget id tags
#check_list are the 0's and digits of the seed values
def check_conf(self):
    # iterate over rows
    for widgets, check_values in zip(self.nums_list, self.check_list):
        #iterate over columns
        for widget, check_value in zip(widgets, check_values):
            if widget.get().isdigit():
                if widget.get() == check_value:
                    widget.config(background = 'red')

.get()
在做什么?我在tkinter中使用一个9 x 9的条目小部件网格。get()正在获取条目Widget中的值。为什么需要强制转换为int进行比较?不完全确定您的代码在做什么,但将可能的位置存储在dict中作为元组可能更容易。您发布的代码是否有效?我发现我正在检查文件的种子值是否等于这些条目,这显然是正确的。我需要创建一个包含所有当前条目的新列表,并检查新条目是否已经在特定的行或列中。输入错误(widget,而不是widget)是故意的吗?@badp。。。只是没注意我的名字,谢谢你指出我的名字。