MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / Grid

Class Grid

example_code/item_075.py:54–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52EMPTY = "-"
53
54class Grid:
55 def __init__(self, height, width):
56 self.height = height
57 self.width = width
58 self.rows = []
59 for _ in range(self.height):
60 self.rows.append([EMPTY] * self.width)
61
62 def get(self, y, x):
63 return self.rows[y % self.height][x % self.width]
64
65 def set(self, y, x, state):
66 self.rows[y % self.height][x % self.width] = state
67
68 def __str__(self):
69 output = ""
70 for row in self.rows:
71 for cell in row:
72 output += cell
73 output += "\n"
74 return output
75
76
77def count_neighbors(y, x, get_cell):

Callers 2

simulateFunction · 0.70
item_075.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected