How to create lists of 3x3 sudoku block in python

后端 未结 5 1712
长发绾君心
长发绾君心 2021-01-23 11:27

I need help creating a list for each of the 9 3x3 blocks in sudoku. so I have a list of lists representing the original sudoku board (zero means empty):

board=[[         


        
5条回答
  •  长发绾君心
    2021-01-23 12:24

    should work, in python3 you might replace "(m/3)*3" with "int(m/3)*3"

    [[board[(m/3)*3+i][(m%3)*3+j] for i in range(3) for j in range(3)] for m in range(9)]
    

提交回复
热议问题