python list:某些项目不会被覆盖...为什么?

时间:2019-12-26 16:17:13

标签: python list

我放弃了这一点: 为什么循环的“ else:”部分不会覆盖所有初始的[0]数组?

origfile = open("sudoku_test.txt", "r")

felder = [[[0]]*9 for _ in range(9)]
print (felder)

buffer = origfile.readlines()

for i in range(9):
    words = buffer[i].split()
    for j in range(9):
        zahl = int(words[j])
        print ("Zahl = ", zahl)
        if zahl != 0:
            felder[i][j]= [zahl]
            print("if   felder[",i,"][",j,"]=",felder[i][j])
        else:
            felder[i][j]=[1,2,3,4,5,6,7,8,9]
            print("else felder[",i,"][",j,"]: ",felder[j][j])
origfile.close()

输入文件“ sudoku_test.txt”是一个用空格分隔的数独:

5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 0

0 个答案:

没有答案