def get_poss_containers(
    target : str,
    contents : dict[str, dict[str, int]]
    ) -> list[str]:
    """Returns a list of all bags which can contain a bag of a given color."""

    to_check = [target]
    valid = set()
    while to_check:
        target_color = to_check.pop()

        for cont_color in contents:
            if cont_color not in valid and target_color in contents[cont_color]:
                valid.add(cont_color)
                to_check.append(cont_color)
    
    return list(valid)