title: Python: Appending using index referencing of a list in a for loop
body: <p>I am trying to use the index of a list (<code>codes</code>) to append the corresponding letter from the dictionary (<code>keys</code>) to a new list (<code>decodedlist</code>) using a <code>for</code> loop.</p>
  
  <p>After using trial and error, I realised I need to use a <code>i-1</code> in <code>decodedlist.append(keys[codes[i-1]])</code> to get the result I want (<code>abcde</code>).</p>
  
  <p>I can't figure out why and I am curious if there are alternative/ more efficient ways of coding this.</p>
  
  <pre><code>import re
  
  samplecode='''
  1asd 2asd as3d 4 asd5asd'''
  
  codes = re.findall(r'\d{1,2}',samplecode)  
  codes = list(map(int,codes))
  
  keys = {1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j'}
  
  decodedlist=[]  
      for i in codes:  
      decodedlist.append(keys[codes[i-1]])
  
  decodedstr=''.join(decodedlist)  
  print(decodedstr)
  </code></pre>