Generating balanced parenthesis code in python