title: Fastest way to calculate the centroid of a set of coordinate tuples in python without numpy
body: <p>I've been working on a project that is incredibly time sensitive (that unfortunately has to be in python) and one of the functions that is used extensively is a function that calculates the centroid of a list of (x, y) tuples. To illustrate:</p>
  
  <pre><code>def centroid(*points):
      x_coords = [p[0] for p in points]
      y_coords = [p[1] for p in points]
      _len = len(points)
      centroid_x = sum(x_coords)/_len
      centroid_y = sum(y_coords)/_len
      return [centroid_x, centroid_y]
  </code></pre>
  
  <p>where</p>
  
  <pre><code>&gt;&gt;&gt; centroid((0, 0), (10, 0), (10, 10), (0, 10))
  [5, 5]
  </code></pre>
  
  <p>This function runs fairly quickly, the above example completing in an average of 1.49e-05 seconds on my system but I'm looking for the fastest way to calculate the centroid. Do you have any ideas?</p>
  
  <p>One of the other solutions I had was to do the following (where <code>l</code> is the list of tuples):</p>
  
  <pre><code>map(len(l).__rtruediv__, map(sum, zip(*l)))
  </code></pre>
  
  <p>Which runs in between 1.01e-05 and 9.6e-06 seconds, but unfortunately converting to a list (by surrounding the whole statement in <code>list( ... )</code>) nearly <em>doubles</em> computation time.</p>
  
  <p>EDIT: Suggestions are welcome in pure python BUT NOT numpy.</p>
  
  <p>EDIT2: Just found out that if a separate variable is kept for the length of the list of tuples, then my above implementation with <code>map</code> runs reliably under 9.2e-06 seconds, but there's still the problem of converting back to a list.</p>
  
  <p>EDIT3:</p>
  
  <p>Now I'm only accepting answers in pure python, NOT in numpy (sorry to those that already answered in numpy!)</p>