Project Euler Problem 5 Performance I'm hoping for suggestions of a concise way to write my list comprehension filter in the first solution.
I would also appreciate insight on the underlying reasons for some performance differences in my solutions for Problem 5 (https://projecteuler.net/problem=5):

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

This first solution takes around 1.5 seconds on my laptop and the other takes 7.5 seconds.
#Project Euler problem 5
import time
start = time.time()
def smallestFactor(start):
#list comprehension filters out numbers not divisible by 11-20
    options = [i for i in range(start, start + 1000000, 20)\
    if i % 20 == 0 and i % 19 == 0 \
    and i % 18 == 0 and i % 17 == 0 \
    and i % 16 == 0 and i % 15 == 0 \
    and i % 14 == 0 and i % 13 == 0 \
    and i % 12 == 0 and i % 11 == 0]
#return if LCM found
    if len(options) &gt; 0:
        print(options[0])
        return options[0]
#recursion with larger numbers if not found
    else:
        smallestFactor(start + 1000000)
smallestFactor(2520)
end = time.time()
print(&quot;Speed: &quot; + str(end - start))

My second solution instead uses a function as the list filter. The speed difference may be trivial, but I'm curious about why it takes longer to invoke a function which otherwise performs a similar filtering task as a series of conditionals written directly into the list comprehension.
#Project Euler problem 5
import time
start = time.time()
factors = [i for i in range(20,9,-1)]
def check(num):
#loop 20-11
    for n in factors:
#check modulus, break or return at end of list
        if num % n == 0 and n != factors[len(factors) - 1]:
            continue
        if num % n == 0 and n == factors[len(factors) - 1]:
            return num
        else:
            break
def smallestFactor(start):
#list comprehension filters out numbers not divisible by 11-20
    options = [i for i in range(start, start + 1000000, 20) if check(i) == i] 
#return if LCM found
    if len(options) &gt; 0:
        print(options[0])
        return options[0]
#recursion with larger numbers if not found
    else:
        smallestFactor(start + 1000000)
smallestFactor(2520)
end = time.time()
print(&quot;Speed: &quot; + str(end - start))
You should care about prime factors. Take the prime factors of one to ten, and 2520:


1: none
2: 2
3: 3
4: 2, 2
5: 5
6: 2, 3
7: 7
8: 2, 2, 2
9: 3, 3
10: 2, 5
2520: 2, 2, 2, 3, 3, 5, 7


You should notice that each prime factor appears in all the divisors. So, 2520 is divisible by 8, as it contains the factors 2, 2, and 2.
The remainder will be the product of 3, 3, 5, and 7.

And so you should make a naive prime factors function. After that, you want to get the prime factors of the divisors, and make a dictionary of prime factors for the smallest multiple of the divisors.

Where a simple solution such as the following, is 20000 times faster than the code in your question.

import collections
from operator import mul
from functools import reduce


def prime_factors(num):
    div = 2
    while num &gt; 1:
        if num % div:
            div += 1
            continue
        yield div
        num /= div


def gen_smallest_divisable(divisors):
    factors = collections.defaultdict(int)
    Counter = collections.Counter
    for divisor in divisors:
        div_factors = Counter(prime_factors(divisor))
        for number, amount in div_factors.items():
            factors[number] = max(factors[number], amount)
    return reduce(mul, (n ** a for n, a in factors.items()))

def smallest_multiple(multiple):
    return gen_smallest_divisable(range(1, multiple + 1))





  but I'm curious about why it takes longer to invoke a function which otherwise performs a similar filtering task as a series of conditionals written directly into the list comprehension.


Just take it at face value, calling functions is slow. Also comprehensions do some magic when passed to the AST, which may speed them up. But 6 seconds for the creation of 11650000 stack frames doesn't seem unreasonable to me.

If you wanted to stick with your method, I'd highly recommend you use itertools.count, as then you don't need your recursion. And you won't test a couple thousand numbers after finding your match.

I'd also make a divisors list, to simplify things. Which has a performance cost, due to using any.

import itertools

def smallest_factor(start):
    divisors = range(11, 21)
    options = (i for i in itertools.count(start, 20)
               if not any(i % d for d in divisors))
    return next(options)