3 ms·
Generators are similarly confusing to visualize... http://pythontutor.com/visualize.html#code=def+fib(n)%3A%0A++++i+%3D+0%0A++++a,+b+%3D+(0,+1)%0A++++while+i+%3
by agentultra 14y ago
Generators are similarly confusing to visualize...
http://pythontutor.com/visualize.html#code=def+fib(n)%3A%0A++++i+%3D+0%0A++++a,+b+%3D+(0,+1)%0A++++while+i+%3C%3D+n%3A%0A++++++++yield+b%0A++++++++i+%2B%3D+1%0A++++++++a,+b+%3D+(b,+b%2Ba)%0A%0A++++++++%0Afor+x+in+fib(8)%3A%0A++++print+x&mode=display&cumulative=false&py=2&curInstr=0 http://pythontutor.com/visualize.html#code=def+fib(n)%3A%0A+...
- anonymous 14y agoIt does look a bit confusing, but it does step through the program in the order it executes. Unlike list comprehension, where it completely misses some instructions.