Nested loops and python programming for sudoku puzzle -


what code can write nested loops print row, column , number each non-empty location in bd.

bd = [ [ '1', '.', '.', '.', '2', '.', '.', '3', '7'],        [ '.', '6', '.', '.', '.', '5', '1', '4', '.'],        [ '.', '5', '.', '.', '.', '.', '.', '2', '9'],        [ '.', '.', '.', '9', '.', '.', '4', '.', '.'],        [ '.', '.', '4', '1', '.', '3', '7', '.', '.'],        [ '.', '.', '1', '.', '.', '4', '.', '.', '.'],        [ '4', '3', '.', '.', '.', '.', '.', '1', '.'],        [ '.', '1', '7', '5', '.', '.', '.', '8', '.'],        [ '2', '8', '.', '.', '4', '.', '.', '.', '6'] ] 

output should

(0,0) has 1 

..and on rest of bd table

give try:

for row, items in enumerate(bd):     col, value in enumerate(items):         if value != ".":             print "(%s, %s) has %s" % (row, col, value) 

prints:

(0, 0) has 1 (0, 4) has 2 (0, 7) has 3 (0, 8) has 7 (1, 1) has 6 ... 

hope helps.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -