title: How to save a list to a file and read it as a list type?
body: <p>Say I have the list <code>score = [1,2,3,4,5]</code> and it gets changed while my program is running. How could I save it to a file so that next time the program is run I can access the changed list as a <code>list</code> type?</p>
  <p>I have tried:</p>
  <pre><code>score=[1,2,3,4,5]
  
  with open(&quot;file.txt&quot;, 'w') as f:
      for s in score:
          f.write(str(s) + '\n')
  
  with open(&quot;file.txt&quot;, 'r') as f:
      score = [line.rstrip('\n') for line in f]
  
  
  print(score)
  </code></pre>
  <p>But this results in the elements in the list being strings not integers.</p>