title: How to save an array to a file
body: <p>I want to know how to save an array to a file. You already helped me a lot, but I have more naive questions (I'm new to Python):</p>
  
  <pre><code>@&lt;TRIPOS&gt;MOLECULE 
  NAME123 
  line3 
  line4 
  line5 
  line6 
  @&lt;TRIPOS&gt;MOLECULE 
  NAME434543 
  line3 
  line4 
  line5 
  @&lt;TRIPOS&gt;MOLECULE 
  NAME343566 
  line3 
  line4 
  </code></pre>
  
  <p>I am currently have this code, but it's save only the <strong>last item</strong> from the array no the all listed in the <code>items_grep</code>. How to fix this?</p>
  
  <pre><code>items = []
  with open("test.txt", mode="r") as itemfile: 
      for line in itemfile: 
          if line.startswith("@&lt;TRIPOS&gt;MOLECULE"): 
              items.append([]) 
              items[-1].append(line) 
          else: 
              items[-1].append(line)      
  #
  # list to grep
  items_grep = open("list.txt", mode="r").readlines()
  # writing files
  for i in items:
      if i[1] in items_grep:
          open("grep.txt", mode="w").write("".join(i))
  </code></pre>
  
  <p>Thank you in advance!</p>