get elements in "AND" in logic string with Python -
i want parse logic strings , combinations of elements in "and" logic. instance, string '( , ( b or c ) )' should [[a,b],[a,c]] , string '( , b , ( c or d , f ) or f , g )' should [[a,b,c],[a,b,d,f],[f,g]]. i'm trying use pyparsing. following post here parsing complex logical expression in pyparsing in binary tree fashion manage nested list letters grouped according preferences ("and" has preference on "or", , parenthesis overrides this): import pyparsing pp complex_expr = pp.forward() vars = pp.word(pp.alphas, pp.alphanums + "_") | pp.regex(r"[+-]?\d+(:?\.\d*)?(:?[ee][+-]?\d+)?").setname('proteins') clause = pp.group(vars ^ (pp.suppress("(") + complex_expr + pp.suppress(")") )) expr = pp.operatorprecedence(clause,[ ("and", 2, pp.opassoc.left, ), ("or", 2, pp.opassoc.left, ),]) #print expr complex_expr ...