5 ms·
> generally the solution for languages without generators is to have your traversal build a list Yes, but then you move from O(1) to O(n) in memory usage. And
by ajuc 5y ago
> generally the solution for languages without generators is to have your traversal build a list
Yes, but then you move from O(1) to O(n) in memory usage. And if you want to optimize it you have to restructure your code, when in python lists and generators are drop-in replacements.
- justinpombrio 5y agoAlso, producing a list doesn't work very well as a substitute for infinite generators.
- greggyb 5y agoUntil you want to walk the generator twice -- stateful generators are a design flaw, in my opinion.