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

Class Grid

example_code/item_071.py:56–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

item_071.pyFile · 0.70
simulateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected