find all multiplicands and multipliers for a number

Ian Kelly ian.g.kelly at gmail.com
Wed Apr 15 11:59:51 EDT 2015


On Tue, Apr 14, 2015 at 8:37 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
>> def turner():
>>     nums = itertools.count(2)
>>     while True:
>>         prime = next(nums)
>>         yield prime
>>         nums = filter(lambda v, p=prime: (v % p) != 0, nums)
>
> This is nice, though it will still hit the nesting limit about equally
> soon, because of the nested filters.  I like the faster versions in the
> O'Neill paper.

Nope. You do end up with a lot of nested filter objects, but there's
no recursion in the Python code, which means that you're not piling up
frame objects, and you'll never hit the interpreter's recursion limit.
You might eventually get a seg fault when the C stack space runs out,
however.



More information about the Python-list mailing list