I have python (3.7) code that works, but it's ugly, and I'm sure there's a more elegant way of doing what I want to do. I have 9 3x3 grids that I want to print out (plus some line separators) for a tic-tac-toe game.
I basically want the output to look like this (sample of the first row)
█ █│ │███
█ │ 2 │█ █
█ █│ │███
The code below does this, but it seems like there's a better way, and I'm not sure how to do this in an elegant for loop.
Thanks in advance!
choice_x = [
['█', ' ', '█'],
[' ', '█', ' '],
['█', ' ', '█']
]
choice_o = [
['█', '█', '█'],
['█', ' ', '█'],
['█', '█', '█']
]
v_grid = [
['│'],
['│'],
['│']
]
empty_grid = [
[' ',' ',' '],
[' ','2',' '],
[' ',' ',' ']
]
row1 = [
choice_x, v_grid, empty_grid, v_grid, choice_o
]
#for n in range(0,4):
slice1 = [sublist[0][:3] for sublist in row1]
result = ''.join([''.join(item) for item in slice1])
print(result)
slice2 = [sublist[1][:3] for sublist in row1]
result = ''.join([''.join(item) for item in slice2])
print(result)
slice3 = [sublist[2][:3] for sublist in row1]
result = ''.join([''.join(item) for item in slice3])
print(result)
#end for loop