3 ms·
Compare these instead: for i in range(n): yield i yield from range(n)
by kzrdude 9y ago
Compare these instead:
for i in range(n): yield i
yield from range(n)
- falcolas 9y agoBoth seem quite readable, really. Seems similar to the usual "list comprehensions vs. for loop" arguments; to which I always think "use whichever is readable for the given code".
- marcosdumay 9y agoThe thing about "list comprehensions vs. loop" is that you can compose comprehensions, but you must edit loops to change them. I fail to see how anything similar would apply here.
- kevin_thibedeau 9y agoThe old way hit the interpreter on every loop iteration.