title: Equalizing the elements in a list
body: <p>I'm attempting to equalize a list of elements. In short, I have an array of x length with each element y being in range from 0 - 100000. To accomplish what I'm trying to do, all elements in the list must be relatively equal to each other (as far as is possible). </p>
  
  <p>Here's some sample output of my current function:</p>
  
  <pre><code>&gt;&gt;&gt; equal([1, 4, 1])
  [2, 2, 2]
  &gt;&gt;&gt; equal([2, 4, 5, 9])
  [5, 5, 5, 5]
  &gt;&gt;&gt; equal([2, 2])
  [2, 2]
  &gt;&gt;&gt; equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
  [5, 5, 5, 5, 5, 5, 5, 5, 5]
  &gt;&gt;&gt; equal([2, 4, 6, 8, 10, 20, 30, 40])
  [15, 15, 15, 15, 15, 15, 15, 15]
  &gt;&gt;&gt; equal([343, 452, 948, 283, 394, 238, 283, 984, 236, 847, 203])
  [474, 474, 474, 474, 474, 474, 474, 474, 473, 473, 473]
  </code></pre>
  
  <p>And the associated code:</p>
  
  <pre><code>def equal(l):
      # The number of times we distribute to the new loop
      loops = reduce(lambda x, y: x + y, l)
  
      # Initializes a new list as such: [0, 0, 0 .. len(l)]
      nl = [0 for x in range(len(l))]
  
      # Counts how far we've iterated into our new list
      x = 0
      for i in range(loops):
          # Add 1 to this element and move on to the next element in the list
          nl[x] += 1
          x += 1
  
          # Ensure we don't traverse past the end of the list
          if x &gt; len(nl) - 1:
              x = 0
  
      return nl
  </code></pre>
  
  <p>The problem right now is that once you get to extremely large lists (100+ elements with large values) it gets really slow. Is there some idiom I'm missing here that would make this more efficient? </p>