def adjacent(cell, size=None):
    """
    Return the cooridinates of the cells adjacent to a given cell
    size: [nlines, ncolumns] to avoid returning out-of-bound coordinates
    """
    if size==None:
        return [
            (cell[0]-1, cell[1]  ),
            (cell[0]  , cell[1]-1),
            (cell[0]+1, cell[1]  ),
            (cell[0]  , cell[1]+1)
        ]
    return [adj for adj in adjacent(cell) if (adj[0]>=0 and adj[0]<size[0] and adj[1]>=0 and adj[1]<size[1])]