From here, define a function to compute the prime of 2 or more numbers:
def gcd(a, b):
"""Return greatest common divisor using Euclid's Algorithm."""
while b:
a, b = b, a % b
return a
def lcm(a, b):
"""Return lowest common multiple."""
return a * b // gcd(a, b)
def lcmm(*args):
"""Return lcm of args."""
return reduce(lcm, args)
Next, compute the lcm of your numbers and then iteratively emit numbers. Good thing is, if you know the lcm, you won't have to go over every number in the range.
from math import ceil
def get_multiples(start, end, *args):
lcm = lcmm(*args)
start = max(lcm, lcm * ceil(start / lcm)) # max(..., ...) in case start < lcm
for i in range(start, end + 1, lcm):
yield i
>>> list(get_multiples(1, 300, 6, 10))
[30, 60, 90, 120, 150, 180, 210, 240, 270, 300]
As noted above, this is efficient since it doesn't iterate over every value in the supplied range, and efficiently scales to > 2 values:
>>> list(get_multiples(79, 400, 6, 10, 20))
[120, 180, 240, 300, 360]