How can I print a lists in different lines

I am trying to create a board for the Noughts and Crosses game with a List matrix, but I can not order every list in differents lines in 3x3 raw and columns, can somebody help me please?

''' 
board = [
[ "|_|","|_|","|_|"],
["|_|","|_|","|_|"],
["|_|","|_|","|_|"],  
]

print (board)

'''

Upvotes: 1

Views: 134

Answers (2)

Sash Sinha
Sash Sinha

Reputation: 22473

Maybe you could create a helper function called something like print_current_board where you use str.join to print each row with tabs between the row's cells:

def print_current_board(board):
    for row in board:
        print('\t'.join(row))

board = [
    ["|_|", "|_|", "|_|"],
    ["|_|", "|_|", "|_|"],
    ["|_|", "|_|", "|_|"],
]

print_current_board(board)

Output:

|_| |_| |_|
|_| |_| |_|
|_| |_| |_|

Upvotes: 2

Mayank Awasthi
Mayank Awasthi

Reputation: 89

#You can use End in Print statement:-
def print_current_board(board):
    for row in board:
        for i in row:
            print(i,end='')
        print('')

board = [
    ["|_|", "|_|", "|_|"],
    ["|_|", "|_|", "|_|"],
    ["|_|", "|_|", "|_|"] ]

print_current_board(board)

Upvotes: 0

Related Questions