def print_path(grid, path):
    print('\n'.join(''.join(['{:4}'.format('*' * ((i, j) in path) + str(val
        )) for j, val in enumerate(row)]) for i, row in enumerate(grid)))
Formatting the print of a path in 2d grid