from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

from collections import defaultdict 
from itertools import product


MOVE_OFFSETS = (
              (-1, -2), (1, -2),
    (-2, -1),                    (2, -1),
    (-2,  1),                    (2,  1),
              (-1,  2), (1, 2)             
)

def _legal_moves_from(row, col, board_size):
	for row_offset, col_offset in MOVE_OFFSETS:
		move_row, move_col = row + row_offset, col + col_offset
		if 0 <= move_row < board_size and 0 <= move_col < board_size:
			yield move_row, move_col

def _add_edge(graph_dict, vertex, move_vertex):
	graph_dict[vertex].add(move_vertex)
	graph_dict[move_vertex].add(vertex)

def build_knight_tour_graph(board_size):
    graph_dict = defaultdict(set)
    for row, col in product(xrange(board_size), xrange(board_size)):
    	for move_row, move_col in _legal_moves_from(row, col, board_size):
    		_add_edge(graph_dict, (row, col), (move_row, move_col))
    return graph_dict


def _dfs_traverse(path, current_vertex, graph_dict, total_squares, 
	              sorted_func=None):
	"""Depth First Search traverse."""
	# Including the current square, if we have visited all squares,
    # just return the whole path as the solution.
	if len(path) + 1 == total_squares:
		return path + [current_vertex]

    legal_vertices = graph_dict[current_vertex] - set(path)
    if not legal_vertices:
    	# No legal neighbor vertices, so dead end.
    	return False

    # Then try all valid paths.
    next_vertices = sorted(legal_vertices, sorted_func)

    pass

def knight_tour_dfs(board_size, sorted_func=None):
	graph_dict = build_knight_tour_graph(board_size)
	total_squares = graph_dict * graph_dict
	pass


def main():
    board_size = 5
    graph_dict = build_knight_tour_graph(board_size)
    print(graph_dict)

if __name__ == '__main__':
    main()

@@ -398,17 +398,20 @@
 _size):%0A
-%09
+    
 for row_
@@ -446,18 +446,24 @@
 FFSETS:%0A
-%09%09
+        
 move_row
@@ -510,18 +510,24 @@
 _offset%0A
-%09%09
+        
 if 0 %3C= 
@@ -584,11 +584,20 @@
 ze:%0A
-%09%09%09
+            
 yiel
@@ -666,17 +666,20 @@
 ertex):%0A
-%09
+    
 graph_di
@@ -706,17 +706,20 @@
 vertex)%0A
-%09
+    
 graph_di
@@ -895,17 +895,20 @@
 )):%0A    
-%09
+    
 for move
@@ -970,18 +970,24 @@
 e):%0A    
-%09%09
+        
 _add_edg
@@ -1126,17 +1126,20 @@
 uares, %0A
-%09
+    
         
@@ -1163,17 +1163,20 @@
 =None):%0A
-%09
+    
 %22%22%22Depth
@@ -1202,17 +1202,20 @@
 rse.%22%22%22%0A
-%09
+    
 # Includ
@@ -1320,17 +1320,20 @@
 lution.%0A
-%09
+    
 if len(p
@@ -1363,10 +1363,16 @@
 es:%0A
-%09%09
+        
 retu
@@ -1490,17 +1490,20 @@
 es:%0A    
-%09
+    
 # No leg
@@ -1541,17 +1541,20 @@
 nd.%0A    
-%09
+    
 return F
@@ -1709,17 +1709,20 @@
 =None):%0A
-%09
+    
 graph_di
@@ -1762,17 +1762,20 @@
 d_size)%0A
-%09
+    
 total_sq
@@ -1810,9 +1810,12 @@
 ict%0A
-%09
+    
 pass

Fix indentation