Python script to verify if expression is balanced