I'm wondering if there is a neater way of doing part 3 of my code? I am building a tic-tac-toe game for an assigment and this is the function for checking if there is a line of 3 of X's or O's. So I'm splitting the "board" list which represents the 3x3 gameboard into three lists that represent rows, columns and "corner to corner" lines.
def check_forwin(board,split_list):
#part 1 splice a single list into 3 lists
check_list1 = [tuple(board[i:j]) for i, j in zip([1]+ split_list, split_list)]
#part 2"invert" the list, as in choosing columns
check_list2 = list(zip(check_list1[0],check_list1[1],check_list1[2]))
#part 3 make 2 lists from "corner to corner"
check_list3 = [[],[]]
check_list3[0] = tuple([check_list1[0][0],check_list1[1][1],check_list1[2][2]])
check_list3[1] = tuple([check_list1[0][2],check_list1[1][1],check_list1[2][0]])
return
board = ["#","a","b","c","d","e","f","g","h","i"]
split_list1 = [4, 7, 10]
check_forwin(board,split_list1)
[('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'h', 'i')]
[('a', 'd', 'g'), ('b', 'e', 'h'), ('c', 'f', 'i')]
[('a', 'e', 'i'), ('c', 'e', 'g')]
Interesting question, though "neat" is a very subjective concept... What you think about this?