def make_count_grid(data):
    """
    Takes a 2 or 3d grid of strings representing binary numbers.

    Returns a grid of the same dimensions in which each binary number has been
    replaced by an integer indicating the number of ones that were in that
    number.
    """
    data = deepcopy(data)

    for i in range(len(data)):
        for j in range(len(data[i])):
            for k in range(len(data[i][j])):
                if type(data[i][j][k]) is list:
                    for l in range(len(data[i][j][k])):
                        try:
                            data[i][j][k] = data[i][j][k][l].count("1")
                        except:
                            data[i][j][k] = len(data[i][j][k][l])
                else:
                    try:
                        data[i][j][k] = data[i][j][k].count("1")
                    except:
                        data[i][j][k] = len(data[i][j][k])

    return data
Takes a 2 or 3d grid of strings representing binary numbers.

    Returns a grid of the same dimensions in which each binary number has been
    replaced by an integer indicating the number of ones that were in that
    number.