title: Generate list of range tuples with given boundaries in python
body: <p>[edit] I'm not sure if this better off to codereview, if so, please migrate :) thanks!</p>
  
  <p>So we were sitting here, working on a semi-academic problem.</p>
  
  <p>Given a <code>start</code>, <code>stop</code> and <code>step</code>, generate a list of range tuples, so that</p>
  
  <pre><code>gen_range(100, 140, 10)
  </code></pre>
  
  <p>would produce</p>
  
  <pre><code>[(100, 110), (110, 120), (120, 130), (130, 140)]
  </code></pre>
  
  <p>also, given then fact that it should work on, say, iterating 500M integers with a step of 100 and not take forever.</p>
  
  <p>The implementation I've come up with is as follows:</p>
  
  <pre><code>def gen_range(start, stop, step):
      llist = range(start, stop+step, step)
      batch_list = []
  
      if llist[-1] &gt; stop:
          llist[-1] = stop
  
      for a, b in enumerate(llist[:-1]):
          batch_list.append((llist[a], llist[a+1]))
  
      print batch_list
  
  gen_range(100000000,600000000,100)
  </code></pre>
  
  <p>But I can't stop thinking that it can be done in a more efficient (also code-length wise) way. Any suggestions?</p>
  
  <p>[edit]</p>
  
  <p>One thing I forgot to point out. If the range boundary is not equal to the step, i.e. you have a case of:</p>
  
  <pre><code>gen_range(100, 143, 10)
  </code></pre>
  
  <p>the upper boundary should be 143, and not 150, as some answers here would produce, due to <code>range()</code> internals.</p>