Optimizing Python code for Project Euler #5 (LCM of all numbers from 1 to 20) This is my solution for the 5th problem of Project Euler, which asks for the least common multiples of the numbers from 1 to 20 (inclusive). Is there any way to improve the while loop conditional instead of using the sum?

table = range(1, 21)
result = 1
pf = 2
while sum(table) &gt; len(table):
   flag = False
   for x, y in enumerate(table):
      if y % pf == 0:
         table[x] = y/pf 
         flag = True
   if flag:
      result *= pf
   else:
      pf += 1
print result
Your intent is to terminate the loop when all entries in table become 1. This

while sum(table) &gt; len(table):


is a rather obscure way of expressing that intent. I suggest instead

while max(table) &gt; 1:


or the more explicit and short-circuiting

while any(x &gt; 1 for x in table):