from typing import Set models = ( {"a", "b", "c"}, ) DL_ATOMS = set.union(*models) def propagate(atoms: Set[str]) -> Set[str]: atoms = atoms.intersection(DL_ATOMS) sub_models = (model for model in models if atoms <= model) first: set = next(sub_models, None) if first is None: return set() return first.intersection(*sub_models) def check(atoms: Set[str]) -> bool: atoms = atoms.intersection(DL_ATOMS) return atoms in models