find all multiplicands and multipliers for a number

Paul Rubin at nospam.invalid
Tue Apr 14 04:42:03 CEST 2015

Steven D'Aprano <steve+comp.lang.python at> writes:

The methods there are more "mathematical" but probably slower than what
I posted.

Just for laughs, this prints the first 20 primes using Python 3's 
"yield from":

    import itertools

    def sieve(ps):
        p = ps.__next__()
        yield p
        yield from sieve(a for a in ps if a % p != 0)

    primes = sieve(itertools.count(2))

It's not that practical above a few hundred primes, probably.

More information about the Python-list mailing list