usr bin env python coding utf-8 class Matrix object White cells contai

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Matrix(object):
"""
White cells contains False or None,
black cells - True
"""
def __init__(self, size):
self.size = size
self.array = [[False]*size]*size
def __getitem__(self, key):
return self.array[key[0]][key[1]]
def __setitem__(self, key, value):
if value:
self.array[key[0], key[1]] = True
else:
self.array[key[0], key[1]] = False
def __delitem__(self, key):
self.array[key[0], key[1]] = False
if __name__ == "__main__":
matrix = Matrix(10)
matrix[1, 2] = False
print matrix[1, 2]