title: How to decompress a file
body: <p>My code has a file "filefile.txt" which has a compressed sentence in it. The file is laid out like : </p>
  
  <pre><code>1
  2
  3 
  4
  5
  1
  2
  6
  9
  10
  11
  2
  12
  12
  9
  
  This 
  is
  a 
  sentence
  .
  too   
  !
  Yo
  yo
  bling
  </code></pre>
  
  <p>The original text that I want to decompress says "!"</p>
  
  <p>My code says:</p>
  
  <pre><code>fo = open("filefile.txt","r")
  script = fo.readline()
  script2 = fo.readline()
  fo.close()
  script2 = script2.split()
  script = [s.strip("\n") for s in script]
  
  sentencewords = []
  
  while len(script) &gt; 0:
      for p in script:
          sentencewords.append(enumerate(script2.index(p)))
          script.remove(0)
  
  print(sentencewords)
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "F:\Computing code attempts\AT13.py", line 46, in &lt;module&gt;
      sentencewords.append(enumerate(script2.index(p)))
  ValueError: '1' is not in list
  </code></pre>
  
  <p>I need <code>sentencewords</code> to contain "This is a sentence. This is too! Yo yo bling bling!"</p>
  
  <p>I have changed it now but it still doesn't work.
          sentencewords.append(enumerate(script2.enumerate(p)))</p>
  
  <pre><code>'Traceback (most recent call last):
  </code></pre>
  
  <p>File "F:\Computing code attempts\AT13.py", line 46, in 
      sentencewords.append(enumerate(script2.enumerate(p)))
  AttributeError: 'list' object has no attribute 'enumerate''</p>
  
  <p>Does anyone know if there is another way round this problem or how to fix my current code?</p>
  
  <pre><code>fo = open("filefile.txt","r")
  script = fo.readline()
  script2 = fo.readline()
  fo.close()
  script2 = script2.split()
  script = [s.strip("\n") for s in script]
  
  sentencewords = []
  
  indexes = []
  for line in fo:
      if line.strip().isdigit():
          indexes.append(line)
      else:
          break
  
  
  words = [line.strip() for line in fo if line.strip()]
  
  while len(script) &gt; 0:
      for p in script:
          sentencewords.append(words[index-1])
  
  
  print(sentencewords)
  </code></pre>
  
  <p>Updated code but I don't know what the I/O thing means in the latest output from python.</p>
  
  <pre><code>Traceback (most recent call last):
    File "F:/Computing code attempts/attempt14.py", line 45, in &lt;module&gt;
      for line in fo:
  ValueError: I/O operation on closed file.
  </code></pre>
  
  <p>Any suggestions on how to fix my code, I'd be grateful for</p>