Question about generators

Vilya Harvey vilya.harvey at gmail.com
Sun Jul 12 15:55:49 EDT 2009


2009/7/12 Cameron Pulsford <cameron.pulsford at gmail.com>:
> My question is, is it possible to combine those two loops? The primes
> generator I wrote finds all primes up to n, except for 2, 3 and 5, so I must
> check those explicitly. Is there anyway to concatenate the hard coded list
> of [2,3,5] and the generator I wrote so that I don't need two for loops that
> do the same thing?

itertools.chain([2, 3, 5], primes) is what you're looking for, I think.

Vil.



More information about the Python-list mailing list