mappings = (dict(zip(symbols, values)) for values in itertools.product([
    False, True], repeat=len(symbols)))
solutions = [sorted(name for name in mapping if mapping[name]) for mapping in
    mappings if eval(expression, None, mapping)]
get elements in "AND" in logic string with Python