18 ms·
oh I have another anecdote! I was just now looking up Python `iterators` vs `generators`, where I asked: > In Python, what differentiates an iterator from a ge
by AceJohnny2 4y ago
oh I have another anecdote! I was just now looking up Python `iterators` vs `generators`, where I asked:
> In Python, what differentiates an iterator from a generator?
and it answered:
> [...] An iterator can be more flexible than a generator because it can maintain state between calls to __next__(), whereas a generator cannot. For example, an iterator can keep track of its position in a sequence, whereas a generator always starts over from the beginning. [...]
Which is flat-out wrong! Of course a generator can preserve state, otherwise how could it even work! (a generator preserves state implicitly by being a closure)"
(Of course, ChatGPT is an evolving system so yes I provided feedback on this. I'm sure in a year or two, I'll be looking back at this gotcha! and cringing.)