Hi all,
I've been trying to write a programme that solves sudoku problems for a
while now. I'm getting close, but would like to ask a few questions about
the most pythonic way of doing some things.
I've decided to create nested lists (row order, column order and square
order) which correspond with dictionary keys - the values of which are the
numbers given in the puzzle - so I can loop through the dict in different
orders.
I think the first two are OK, but the square order list seems extremely
messy and I would love some pointers. What I have is as follows:

roworder = [[str(j)+str(i) for i in range(9)] for j in range(9)]
colorder = zip(*roworder)
#here comes the problem!
start, index = 0,0
sqorder = []
for i in range(9):
    sqorder.append([])
    for j in range(start, start+3):
        sqorder[i].extend(roworder[j][index:index+3])
    if index == 6:
        index = 0
    else:
        index += 3
    if i == 2 or i == 5:
        start += 3

Any comments at all would be gratefully received.
Thanks in advance
Colin
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to