':type grid: List[List[int]]
:rtype: int'

def islandPerimeter(self, grid):

    (count, repeat) = (0, 0)
    for i in xrange(len(grid)):
        for j in xrange(len(grid[i])):
            if (grid[i][j] == 1):
                count += 1
                if ((i != 0) and (grid[(i - 1)][j] == 1)):
                    repeat += 1
                if ((j != 0) and (grid[i][(j - 1)] == 1)):
                    repeat += 1
    return ((4 * count) - (2 * repeat))
