
Dynamically evaluating simple boolean logic in Python?
1 Expert Answer

Max B. answered 04/06/23
University lecturer & senior engineer tutoring Python, other languages
Unless your logic expression is really really big, converting to a tree and writing an evaluator for it is a very reasonable approach. Depending on the depth, you might hit a stack overflow with the recursive approach.
Where are you getting the input from? What other constraints do you have? That might help shape a solution.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Matthew B.
Can you post the full code?11/12/19