about summary refs log tree commit diff
path: root/users/wpcarro/scratch/facebook/utils.py
blob: 9a3e8a045e88ac78cd7aaed35cafa49b46316086 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def init_table(rows=0, cols=0, default=None):
    table = []
    for row in range(rows):
        x = []
        for col in range(cols):
            x.append(default)
        table.append(x)
    return table

def get(table, row, col, default=0):
    if row < 0 or col < 0:
        return default
    return table[row][col]

def print_table(table):
    result = []
    for row in range(len(table)):
        result.append(' '.join([str(cell) for cell in table[row]]))
    print('\n'.join(result))