Python Battleship 6/19, additional row in brackets


#1

Hello everyone, I have an answer that 6/19 accepted for this lesson but the resulting print has an entire bracketed row in addition to the join.

Here is the code:

board = []

def grid(rows):
  for i in range(5):
  	rows.append(["O"]*5)
  return rows

def print_board(board_in):
  for row in board_in:
    print " ".join(row)
  return row

print print_board(grid(board))

Here is the resulting print:

O O O O O
O O O O O
O O O O O
O O O O O
O O O O O
['O', 'O', 'O', 'O', 'O']

My question is why is there that additional row that isn’t being affected by the print_board function? Can this be fixed from that structure or does it just need a different structure?

Thank you to those of you who comment on these boards, as a now former lurker, I appreciate you!

Thanks @mtf it worked like a charm:

board = []

def grid(rows):
  for i in range(5):
  	rows.append(["O"]*5)
  return rows

def print_board(board_in):
  for row in board_in:
    print " ".join(row)

print_board(grid(board))

Which put out the intended result

O O O O O
O O O O O
O O O O O
O O O O O
O O O O O


#2

No return needed, the function does the printing.

No print needed since the function does the printing. That line is printing the return value (row) after the function has done the printing.