title: Fastest way to xor all integers in a string
body: <p>I am trying to find the fastest way of xor'ing all integers(numerals actually) in a string consecutively. The problem makes me feel that there is an simple and a fast answer I just can't think of. But here what I came up with so far.</p>
  
  <p><strong>Setup:</strong></p>
  
  <pre><code>from operator import xor
  a = "123"
  </code></pre>
  
  <ul>
  <li><p>Regular loop</p>
  
  <pre><code>val = 0
  for i in a:
      val = val ^ int(i)
  print val
  </code></pre></li>
  <li><p><code>operations.xor</code> with <code>reduce</code></p>
  
  <pre><code>reduce(xor, map(int, list(a)))
  </code></pre></li>
  </ul>
  
  <p>I expected the second one to be faster but when the string grows, the difference is almost none. Is there a faster way ?</p>
  
  <p><strong>Note1:</strong> And I would like to know if it is possible using just the integer as <code>123</code> instead of the string <code>"123"</code>. That would be unlogical because I need a list of integers, however sometimes interesting answers appear from places you never expect.</p>
  
  <p><strong>Edit:</strong> Here is the results from the methods suggested so far.</p>
  
  <pre><code>import timeit
  
  setup = """
  from operator import xor
  
  a = "124"
  b = 124
  """
  
  p1 = """
  val = 0
  for i in a:
      val = val ^ int(i)
  val
  """
  
  p2 = """
  reduce(xor, map(int, list(a)))
  """
  
  p3 = """
  val = 0
  for i in xrange(3):
      val = val ^ (b % 10)
      b /= 10
  val
  """
  
  p4 = """
  15 &amp; reduce(xor, map(ord, a))
  """
  print 1, timeit.timeit(p1, setup=setup, number = 100000)
  print 2, timeit.timeit(p2, setup=setup, number = 100000)
  print 3, timeit.timeit(p3, setup=setup, number = 100000)
  print 4, timeit.timeit(p4, setup=setup, number = 100000)
  
  # Gives
  1 0.251768243842
  2 0.377706036384
  3 0.0885620849347
  4 0.140079894386
  </code></pre>
  
  <p>Please also note that using <code>int(a)</code> instead of <code>b</code> in process 3 makes it slower than 4.</p>