Thanks for your help!
While i am trying my very best to understand the logic behind...but my question remains there.
Perhaps let me try to elaborate my concern in a more detailed way.
My understanding of the code is that the below recursion will keep going until i reach the 'flat' layer, i.e. 1
In order to capture it, we have the below code
Then i dun understand what happens next. As you suggested, i thought the code freezes right there and gives us 1. I have to use
Nonetheless, it seems to me that it is the
Sorry for bothering you!
While i am trying my very best to understand the logic behind...but my question remains there.
Perhaps let me try to elaborate my concern in a more detailed way.
My understanding of the code is that the below recursion will keep going until i reach the 'flat' layer, i.e. 1
for sublist in nested: for element in flatten(sublist):At this point, the 'flat' layer cannot be used in
for
again because it is an integer. So a TypeError takes places.In order to capture it, we have the below code
except TypeError: yield nestedIn this case, yield nested will return 1.
Then i dun understand what happens next. As you suggested, i thought the code freezes right there and gives us 1. I have to use
next()
to return the next 'flat' layer.Nonetheless, it seems to me that it is the
yield elementthat gives us 1 instead of
yield nested.
Sorry for bothering you!