title: Fastest way to get a hash from a list?
body: <p>I have a long list of integers that I want to turn into an MD5 hash. What's the quickest way to do this? I have tried two options, both similar. Just wondering if I'm missing an obviously quicker method.</p>
  <pre><code>import random
  import hashlib
  import cPickle as pickle
  
  r = [random.randrange(1, 1000) for _ in range(0, 1000000)]
  
  def method1(r):
      p = pickle.dumps(r, -1)
      return hashlib.md5(p).hexdigest()
  
  def method2(r):
      p = str(r)
      return hashlib.md5(p).hexdigest()
  
  def method3(r):
      p = ','.join(map(str, r))
      return hashlib.md5(p).hexdigest()
      
  </code></pre>
  <p>Then time it in iPython:</p>
  <pre><code>timeit method1(r)
  timeit method2(r)
  timeit method3(r)
  </code></pre>
  <p>Gives me this:</p>
  <pre><code>In [8]: timeit method1(r)
  10 loops, best of 3: 68.7 ms per loop
  
  In [9]: timeit method2(r)
  10 loops, best of 3: 176 ms per loop
  
  In [10]: timeit method3(r)
  1 loops, best of 3: 270 ms per loop
  </code></pre>
  <p>So, option 1 is the best I've got. But I have to do it a lot and it's currently the rate determining step in my code.</p>
  <p>Any tips or tricks to get a unique hash from a big list quicker than what's here, using Python 2.7?</p>