title: find least common multiple of numbers 1-20
body: <p>I am having some trouble with this algorithm.  I am attempting to find the least common multiple for a given range of numbers.  The following functions find the factors of a number, count the different factors in the number, counts the factors so that I can find the lcm of the range of numbers based on <a href="http://www.math.com/school/subject1/lessons/S1U3L3DP.html" rel="nofollow">this</a> algorithm, and then finally calculates the lcm; however, if you run this code, the print statement at the bottom does not print the correct answer.  Instead I get a number that I KNOW for sure is not right.  I mainly need a second set of eyes to point out the problem with this code.  Can anyone help?</p>
  
  <pre><code>from collections import defaultdict
  
  def factors_of(number):
      factors = [];
      i = 2
      while number &gt;= 2:
          if number % i == 0:
              factors.append(i)
              number = number / i
          else:
              i += 1
      return factors
  
  def count_factors(number):
      count = {}
      factors = factors_of(number)
      for factor in factors:
          if not factor in count:
              count[factor] = 1
          else:
              count[factor] += 1
      return count
  
  def count_factors_of_numbers_in_range(start, stop):
      count = defaultdict(int)
      for number in range(start, stop):
          factor_count = count_factors(number)
          for key in factor_count:
              if count[key] &lt; factor_count[key]:
                  count[key] = factor_count[key]
      return dict(count)
  
  def find_lcm_of_numbers_in_range(start, stop):
      count = count_factors_of_numbers_in_range(start, stop)
      lcm = 1
      for key in count:
          total = count[key] * key
          lcm = total * lcm
      return lcm
  
  print find_lcm_of_numbers_in_range(1, 21)
  </code></pre>