"Danny Colligan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Now that we're on the subject, what are the advantages of using > generators over, say, list comprehensions or for loops? It seems to me > that virtually all (I won't say everything) the examples I've seen can > be done just as easily without using generators.
The more trivial the example, the harder it is to see the advantage. Suppose you wanted to sum the first 10000 primes. A quick Google fins you Wensheng Wang's recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366178 Just add print sum(primes(10000)), and you're done. -- http://mail.python.org/mailman/listinfo/python-list