title: What is the pythonic way to detect the last element in a 'for' loop?
body: <p>I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only <em>between</em> elements, being suppressed in the last one.</p>
  
  <p>Here is how I currently do it:</p>
  
  <pre><code>for i, data in enumerate(data_list):
      code_that_is_done_for_every_element
      if i != len(data_list) - 1:
          code_that_is_done_between_elements
  </code></pre>
  
  <p>Is there any better way?</p>
  
  <p>Note: I don't want to make it with hacks such as using <code>reduce</code>. <code>;)</code></p>