class Table(object):

    def __init__(self):
        self.d = collections.defaultdict(dict)

def add(self, row, col, val):
    self.d[row][col] = val

def get(self, row, col, default=None):
    return self.d[row].get(col, default)

def inrow(self, row, col):
    return col in self.d[row]
Таблица в памяти Python