title: what's a better way to read information from TXT and put into list in python
body: <p>I have a TXT in following form, which is the data for <a href="https://en.wikipedia.org/wiki/Knapsack_problem" rel="nofollow noreferrer">Knapsack problem</a>:</p>
  <ul>
  <li><code>100</code> in first row represents the total capacity</li>
  <li><code>10</code> in first row represent the number of items</li>
  <li>Then each row contains the value and weight for each item. For example, the second row <code>9 46</code> represents an item with 9 in value and 46 in weight.</li>
  </ul>
  <blockquote>
  <p>100 10\n 9 46\n 28 31\n 15 42\n 13 19\n 31 48\n 36 11\n 13 27\n 42 17\n 28 19\n 1 31</p>
  </blockquote>
  <p>I use the code below to read the information and put it into separate list.</p>
  <pre class="lang-py prettyprint-override"><code>with open(path) as f:
  
      capacity,total_number = f.readline().split(' ')
      capacity = int(capacity)
      total_number = int(total_number)
      value_list = [int(x.split(' ')[0]) for x in f.readlines()]
      f.seek(0)
      next(f)
      weight_list = [int(x.split(' ')[1]) for x in f.readlines()]
      assert total_number==len(weight_list)==len(value_list)
  </code></pre>
  <p>But it kinds feel redundant in a way.</p>
  <p>Ccould anyone help me with improvements on that?</p>