Do you have in mind the good old TicTacToe?

Assuming that you get all the data in one array, you put a space around each value, `|` as a columns separator and multiple `-` as rows separator, with something like `["O", "X", " ", " ", "X", " ", "X", "O", " "]` you should be returning this structure (inclusive of new lines):

```
 O | X |   
-----------
   | X |   
-----------
 X | O |   
```

Now, to spice up things a bit, we are going to expand our board well beyond a trivial `3` x `3` square and we will accept rectangles of big sizes, still all as a long linear array.

For example, for `"O", "X", " ", " ", "X", " ", "X", "O", " ", "O"]` (same as above, just one extra `"O"`) and knowing that the length of each row is `5`, you will be returning

```
 O | X |   |   | X 
-------------------
   | X | O |   | O 
```

And worry not about missing elements, as the array/list/vector length is always going to be a multiple of the width.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def display_board(board, width):
	

Solutions:
def display_board(board, width):
	board = [c.center(3) for c in board]
	rows = ['|'.join(board[n:n + width]) for n in range(0, len(board), width)]
	return ('\n' + '-' * (4 * width - 1) + '\n').join(rows)


def display_board(board, width):
	line = f"\n{'-' * (4 * width - 1)}\n"
	return line.join(('|'.join((f' {c} ' for c in row)) for row in (board[i:i + width] for i in range(0, len(board), width))))


def display_board(board, width):
	output = ''
	separator = width * 3 + (width - 1)
	for i in range(len(board)):
		output += f' {board[i]} '
		if i + 1 < len(board):
			if (i + 1) % width == 0:
				output += '\n' + '-' * separator + '\n'
			else:
				output += '|'
	return output


def display_board(board, width):
	row = lambda i: f" {' | '.join(board[i:i + width])} "
	sep = f"\n{'':-^{4 * width - 1}}\n"
	return sep.join((row(i) for i in range(0, len(board), width)))


def display_board(board, width):
	return ('\n' + '-' * (4 * width - 1) + '\n').join(['|'.join([' ' + board[i * width + j] + ' ' for j in range(width)]) for i in range(int(len(board) / width))])


def display_board(board, width):
	lines = [' ' + ' | '.join(board[i:i + width]) + ' ' for i in range(0, len(board), width)]
	return ('\n' + '-' * len(lines[0]) + '\n').join(lines)


def display_board(board, w):
	re = []
	for i in range(0, len(board), w):
		re.append('|'.join((' {} '.format(e) for e in board[i:i + w])))
	return ('\n' + '-' * len(re[0]) + '\n').join(re)


display_board = lambda a, n: ' %s ' % (' \n' + (4 * n - 1) * '-' + '\n ').join(map(' | '.join, zip(*[iter(a)] * n)))


display_board = lambda b, w: f"\n{'-' * (4 * w - 1)}\n".join(['|'.join((' ' + c + ' ' for c in b[i:i + w])) for i in range(0, len(b) - 1, w)])