def probability_in_subspace(wavefunc: dict, subspace: list) -> float:
    """
    Calculates the probability that the wavefunction 'wavefunc' lies in 'subspace'
    Note: This only works for subspaces aligned with the comp. basis.
    :param wavefunc: dict, contains complex amplitudes of the wavefunction
                           in computational basis states
    :param subspace: list, list containing the computational basis vectors which
                           span the subspace
    :return: float
    """
    assert isinstance(wavefunc, dict), 'Please provide your state as a dict.'
    assert isinstance(subspace, list), 'Please provide subspace as a list of str.'

    # Deal with empty subspace:
    if not subspace:
        return 0
    assert isinstance(subspace[0], str), 'Please provide subspace as a list of str.'
    assert len(wavefunc) >= len(subspace)
    subspace_prob = 0.

    # add up probabilities for all basisvectors in the subspace
    for basisvector in subspace:
        basisvector_prob = abs(wavefunc[basisvector]) ** 2
        subspace_prob += basisvector_prob

    return subspace_prob