我开始了一个 suduko 项目,我需要将列表“board”中的所有 0 替换为“”。为什么它不起作用?
我收到此错误:
AttributeError: 'list' object has no attribute 'replace'
我的代码:
board = [[3,7,0,0,5,0,0,0,0],
[0,6,0,0,3,0,2,0,0],
[0,2,9,4,0,0,0,7,8],
[0,0,4,1,7,0,0,8,0],
[0,0,6,3,0,5,9,0,0],
[0,5,0,0,8,4,1,0,0],
[7,1,0,0,0,8,5,6,0],
[0,0,5,0,1,0,0,2,0],
[0,0,0,0,9,0,0,1,3]]
def print_board(board):
pass
a=-1
board=board.replace(0, " ")
for i in board:
a+=1
if a%3==0:
print 25*"*"+""
print "*",i[0],i[1],i[2],"*",i[3],i[4],i[5],"*",i[6],i[7],i[8],"*"
else:
print "*",i[0],i[1],i[2],"*",i[3],i[4],i[5],"*",i[6],i[7],i[8],"*"
print 25*"*"+""