import random
import bisect


def generate_sector(size: int, object_weight: list) -> dict:
    """
    Generates an Sector with Weighted Spawns

    Args:
        size: Int Representing the Size of the Sector (Size X Size)
        object_weight: An Nested List with Object / Value Types

    Examples:
        generate_sector(6, [["*", 50], ["#", 10]]) would output an Map File where * is far more Common than #

    Returns:
        An Dict with Lists inside which Represent the Map Data per Row
    """

    if size is 0:
        raise ValueError("The Sector Size cant be 0")

    size += 1

    output = {}
    placed_player = False
    totals = []
    running_total = 0

    for w in object_weight:
        running_total += w[1]
        totals.append(running_total)

    def next():
        """
        Gets an Random Object from the Object - Weight List
        """
        ran = random.random() * totals[-1]
        i = bisect.bisect_right(totals, ran)
        return object_weight[i][0]

    for x in range(1, size):
        row = []
        for y in range(1, size):
            object = next()
            if placed_player is False and object is "@":
                row.append(object)
                placed_player = True
                continue
            elif placed_player is True and object is "@":
                while object is "@":
                    object = next()
            row.append(object)
        output[x] = row
    return output