I'm writing a Python program to play Tic Tac Toe, using Numpy arrays with "X" represented by 1
and "O" by 0
. The class includes a function to place a mark on the board:
import numpy as np
class Board():
def __init__(self, grid = np.ones((3,3))*np.nan):
self.grid = grid
def place_mark(self, pos, mark):
self.grid[pos[0],pos[1]] = mark
so that, for example,
board = Board()
board.place_mark([0,1], 1)
print board.grid
yields
[[ nan 1. nan]
[ nan nan nan]
[ nan nan nan]]
I was wondering if the pos[0], pos[1]
argument in the place_mark
function could somehow be replaced by the 'unpacked' contents of pos
(which is always a list of length 2). In Ruby this would be done using the splat operator: *pos
, but this does not appear to be valid syntax in Python.