3 ms·
> This is just silly. You can't use a generator twice, just like you can't keep reading from a file. When you've reached EOF, you're done. What does this guy ex
by jules 17y ago
> This is just silly. You can't use a generator twice, just like you can't keep reading from a file. When you've reached EOF, you're done. What does this guy expect, code that magically determines that when you ask for 'next()', you mean 'restart_at_the_beginning()'?
Yes you can't use a generator twice, that's the problem. If you use an imperative next() you have this problem. It can be solved by using lazy lists instead of generators.
- Goladus 17y agoPython is an imperative language. It supports functional style really well but it's definitely not a functional language. So whether it's "wrong" to be unable to use a generator twice is not as obvious as in a functional language.