from typing import List
from typing import Set
from typing import Dict


def get_samples_in_studies(samples: List[str],
                           studies: Set[str],
                           sample_to_study: Dict[str, str]) -> List[str]:
    """
    Find which samples from the list were generated by the given studies

    Arguments
    ---------
    samples: The accessions of all samples
    studies: The studies of interest that generated a subset of samples in the list
    sample_to_study: A mapping between each sample and the study that generated it

    Returns
    -------
    subset_samples: The samples that were generated by a study in `studies`
    """
    subset_samples = [sample for sample in samples if sample_to_study[sample] in studies]
    return subset_samples