I have a list of lists of -
characters which acts as a grid.
I want to change one -
to a Q
per col and row.
Here's what I've got so far:
import pprint
import random # I import these classes
grid = [['-'] for n in range(8)]
for i in range (8):
for j in range(8):
inserPoint = random.randrange(8,8)
if (j == inserPoint or i == inserPoint) and (grid[j] != 'Q' or grid[i] != 'Q'):
grid[i][j] = ('Q')
pprint.pprint(grid) #/ how to print one queen per line
this is my output. As you can see there are too many Q
s on the grid:
[['-','-','-','-','-','-','Q','-'],
['-','-','-','-','Q','Q','-','-']
['-','-','-','-','Q','-','-','-']
['Q','Q','-','-','-','Q','Q','-']
['-','-','Q','-','Q','-','-','-'].