title: Python: IndexError: list index out of range Error
body: <p><strong>Updated, look bottom!</strong></p>
  
  <p>I am stuck! I get a IndexError: list index out of range Error.</p>
  
  <pre><code>def makeInverseIndex(strlist):
      numStrList = list(enumerate(strlist))
      n = 0 
      m = 0 
      dictionary = {}
      while (n &lt; len(strList)-1):
          while (m &lt; len(strlist)-1):
              if numStrList[n][1].split()[m] not in dictionary:
                  dictionary[numStrList[n][1].split()[m]] = {numStrList[n][0]}
                  m = m+1
              elif {numStrList[n][0]} not in dictionary[numStrList[n][1].split()[m]]:
                  dictionary[numStrList[n][1].split()[m]]|{numStrList[n][0]} 
                  m = m+1
          n = n+1                
  return dictionary
  </code></pre>
  
  <p>it gives me this error</p>
  
  <pre><code>&gt;&gt;&gt; makeInverseIndex(s)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "./inverse_index_lab.py", line 23, in makeInverseIndex
      if numStrList[n][1].split()[m] not in dictionary: 
  IndexError: list index out of range
  </code></pre>
  
  <p>I don't get it... what causes this? It happens even when I change the conditions of the while loop. I don't get what is the problem. I am pretty new at this, so explain it like you would if a piece of broccoli asked you this question.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Thanks guys, I forgot to mention examples of input, I want to input something like this:</p>
  
  <pre><code> L=['A B C', 'B C E', 'A E', 'C D A']
  </code></pre>
  
  <p>and get this as output:</p>
  
  <pre><code>D={'A':{0,2,3}, 'B':{0,1}, 'C':{0,3}, 'D':{3}, 'E':{1,2}}
  </code></pre>
  
  <p>so to create a dictionary that shows where in the list you might find a 'A' for example. It should work with a huge list. Do anyone have any tips? I want it to iterate and pick out each letter and then assign them a dictionary value.</p>
  
  <p><strong>Edit number two:</strong></p>
  
  <p>Thanks to great help from you guys my code looks beautiful like this:</p>
  
  <pre><code>def makeInverseIndex(strList):
  numStrList = list(enumerate(strList))
  n = 0
  dictionary = {}
  while (n &lt; len(strList)):
      for word in numStrList[n][1].split():
          if word not in dictionary:
              dictionary[word] = {numStrList[n][0]}
          elif {numStrList[n][0]} not in dictionary[word]:
              dictionary[word]|={numStrList[n][0]} 
      n = n+1                     
  
  return dictionary
  </code></pre>
  
  <p>But I still manage to get this error when I try to run the module:</p>
  
  <pre><code>   &gt;&gt;&gt; makeInverseIndex(L)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "./inverse_index_lab.py", line 21, in makeInverseIndex
      for word in numStrList[n][1].split():
  NameError: global name 'StrList' is not defined
  </code></pre>
  
  <p>I do not see where the error can come from.</p>