i working on sudoku solver in python. coordinates of boxes given code:
for row in range(1, 10): column in range(1,10): boxes.append((row, column))
later, have list of tuples in format of (row, column, box, number). need organize them in order of first list. both same length, though make new list finding each (row, column) pair in larger list. in other words, item (1, 1), want find tuple in other list item 0 '1' , item 1 '1'.
how can this?
i believe should work finding (row, column) pair:
entry = [e e in tuple_list if (e[0] == row , e[1] == column)][0]
you end list of entries e
match (1, 1) pattern , first of these using [0]
.
use in loop find each 1 individually:
sorted_tuple_list = [] row in range(1, 10): column in range(1,10): entry = [e e in tuple_list if (e[0] == row , e[1] == column)][0] sorted_tuple_list.append(entry)
Comments
Post a Comment