last day (15 days later) » 

7:30 PM
0
Q: Generate parentheses solution

EMLI have coded a solution to build all valid permutations of parentheses. My code is below. I have a question on my code based on a comment by my PEP8 checker. It said that there was no need to include the line return anywhere in the code (initially I included one). The solution works but I hav...

 
At which line did you originally include the return statement?
 
EML
After the line build_parentheses.counter += 1 in the base-case if....
Thanks. I have edited the post
 
Do you happen to have a code snippet where you did in fact needed to use the returnstatement? This way, we can compare that code with your current snippet.
 
EML
Sorry. Yes. The following post I made on code-review is a nice comparison. codereview.stackexchange.com/questions/221554/…
 
The key difference is you are using an else: block here, rendering the returnobsolete.
 
EML
7:30 PM
I see. So because I reach the end of an if statment, does it automatically return?
 
No, but because all remaining code in the function is in the else, there is no more reachable code detected. If you have more questions about the scope of code blocks, take it to chat :)
Hi, is everything clear for you now?
 
EML
Oh ok. So to clarify my question "because I reach the end of an if statment, does it automatically return?" if I have an if statement that is in the outer "layer" of a function and that if statement (or else statement for that matter) finishes, then it returns?
By "outer-layer" I mean something like

def function ():
if: ....
else:....
 
after the end of any 'if' statement, it continues with code after all 'else if' and 'else' blocks of that 'if'
so in this example you post, since there is no other code after 'else' has finished, it will exit the function
 
EML
I see. That makes sense. Thanks :)
Really appreciate your help :)
 
Glad to be able to help :) Take care
 

last day (15 days later) »