def iterate_squarings(x, powers_to_calculate):
    """
    Repeatedly square x.

    The values in the "powers_to_calculate" (an iterator),
    which must be increasing, will be returned.
    """

    powers_calculated = {}
    powers_to_calculate = sorted(powers_to_calculate)

    # Repeatedly square x
    previous_power = 0
    for current_power in powers_to_calculate:
        for _ in range(current_power - previous_power):
            x = pow(x, 2)
        powers_calculated[current_power] = x
        previous_power = current_power
    return powers_calculated