unexpected error(Solved) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

unexpected error(Solved)

Ok, I can't understand why this admittedly unnecessarily complicated one liner cannot be used in a for loop. It works when arguments are passed directly but raises error in the for loop. Is this a limitation of the walrus operator or the lambda scope getting messed up? Any ideas? I like to experiment a bit and push the code to see what it takes to break it. It breaks here... (Solved, thanks to insight provided by Jay Matthews ' feedback.) https://code.sololearn.com/cve349Ch6v5k/?ref=app https://code.sololearn.com/cPp7I7Eh68eO/?ref=app

1st Feb 2023, 4:49 AM
Bob_Li
Bob_Li - avatar
3 Answers
0
Jay Matthews you're right! so it's not about the for range, but about arguments fed to it. it fails on mtx(0) and mtx(1). what's going on?
1st Feb 2023, 7:18 AM
Bob_Li
Bob_Li - avatar
0
Jay Matthews agreed. Maybe the lambda was wrongly written? The commented out functions below that all works down to 0. Nesting lambdas is tricky.
1st Feb 2023, 7:23 AM
Bob_Li
Bob_Li - avatar
0
Jay Matthews Thanks to your insight, I decided to take out the inner nested lambda and put it in the outer lambda parameter, so the nesting weirdness go away.
1st Feb 2023, 8:21 AM
Bob_Li
Bob_Li - avatar