Re: Comprehensions
Paul Prescod <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Mark Hahn wrote: > Some generator/iterator questions (warning, late night questions)... > > 1) Should functions like split be returning iterators instead of lists? > What if you run split on a 100 megabyte file? Can you run split on a file > instead of a string in memory? Yes, Guido has said he would use iterators more in the standard library if he could do it all again. > 2) Should we visit every function that returns a list and change it to > return an iterator? Most...not list() or sort(). > 3) What is the difference between an iterator and a generator? Does a > generator generate values or does it generate iterator objects? Enquiring > minds want to know. A generator is a kind of iterator created by either a generator function or a generator expression. There isn't anything deep that unites generator functions and generator expressions other than terminology. The functions and expressions both "generate" values. But they do so by creating objects that implement the iterator interface (i.e. are interators). Paul Prescod