title: Pythonic vs Unpythonic
body: <p>Consider these two functions that does the following: Given a word, it produces a list where every position in the word is replaced by every character in the alphabet</p>
  
  <pre><code>alphabet = 'abcdefghijklmnopqrstuvwxyz'
  </code></pre>
  
  <p>Version 1 (Pythonic):</p>
  
  <pre><code>def replace1_word( word ):
      return [word[:w]+alphabet[i]+word[w+1:] 
              for w in range(len(word)) 
              for i in range(len(alphabet))]
  </code></pre>
  
  <p>Version 2 (Unpythonic):</p>
  
  <pre><code>def replace1_word2( word ):
      res=[]
      for w in range(len(word)):
          for i in range(len(alphabet)):
              res.append( word[:w] + alphabet[i] + word[w+1:] )
      return res
  </code></pre>
  
  <p>I used <code>timeit</code> module to run it 1000 times and measure the timings and the average runtime difference comes down to be between <code>0.028</code> milliseconds to <code>0.040</code> milliseconds.</p>
  
  <p>My questions is which part/line of the code is costly in the second version and why? They both "seem to" work the same way and return the same result in list format.</p>