import random size = random.randint(3,8) x, y = random.randint(1,size-1), random.randint(1,size-1) board = [["o"] * size for i in range(size)] board[x][y] = "x" for row in board: print " ".join(row) print "" def getPosition(): # iterate over all rows in the board for i in range(len(board)): # check if the "x" character is present in the row if "x" in board[i]: # return the "x" position return i, board[i].index("x") print getPosition()