def analyse(expression):
    symbols = set(re.findall('\\b[A-Z]\\b', expression))
mappings = (dict(zip(symbols, values)) for values in itertools.product([
    False, True], repeat=len(symbols)))
get elements in "AND" in logic string with Python