anirudh
anirudh

Reputation: 562

split a boolean expression by the outermost AND operators

In python how can I split a boolean expression containing AND, OR clauses by the AND operator in lesser lines of code. is there some function or module to support these kind of operations?

eg. if the expression is -- ((a AND b) OR (c AND d)) AND (d OR a) i just want to split it by the outer most AND's ie {((a AND b) OR (c AND d)), (d OR a)}

PS - the AND and OR are python operators, not strings.

Upvotes: 0

Views: 529

Answers (1)

aquavitae
aquavitae

Reputation: 19154

If you mean something like

>>> some_operation((a and b) and c)
(a and b), c

then you can't. The expression is evaluated before any function could be called, and there is no syntax to do this in python. I'm not really sure why you'd want to.

If this is not what you mean, then please explain.

Upvotes: 1

Related Questions