In Python, is there a way to test if a number is divisible by multiple numbers without writing out the modulo operation for each factor?
More specifically, is there
if all(i % n == 0 for n in reversed(xrange(11, 101))):
print(i)
Only a slightly modified version of the duplicate answers already given: xrange
returns an object that generates the numbers in the range on demand (slightly faster than range
and more memory efficient). If performance is important here, which it often is for mathematical code snippets like this bit, the reverse iterator will check the bigger numbers first. This is more likely to kick you out of the all()
function sooner.