creating two separate lists read from a file in python
<p>Can i please know how the data from a file can be split into two separate lists. For example,
file contains data as 1,2,3,4;5,6,7 </p>

<pre><code>my code:

for num in open('filename','r'):
  list1 = num.strip(';').split()
</code></pre>

<p>Here , i want a new list before semi colon (i.e) [1,2,3,4] and new list after semi colon (i.e) [5,6,7]</p>

<p>To get the final list you need to split on <code>","</code> as well (and probably <code>map()</code> the result to <code>int()</code>):</p>

<pre><code>with open("filename") as f: 
     for line in f:
         list1, list2 = [x.split(",") for x in line.rstrip().split(";")]
</code></pre>

python python-2.7 python-3.x