Python: Reading text file and splitting into different lists
<p>I have a text file which contains two lines of text. Each line contains student names separated by a comma.</p>

<p>I'm trying to write a program which will read each line and convert it to a list. My solution seems to make two lists but I don't know how to differentiate between the two as both lists are called "filelist". For example I may need to append to the second list. How would I differentiate between the two?</p>

<p>Or is it possible for it to create completely separate lists with different names? I want the program to be able to handle many lines in the text file ideally.</p>

<p>My code is:</p>

<pre><code>    filelist=[]

    with open("students.txt") as students:

            for line in students:

                    filelist.append(line.strip().split(","))


    print(filelist)
</code></pre>

<p>two lines to done</p>

<pre><code>with open("file.txt") as f:
    qlist = map(lambda x:x.strip().split(","), f.readlines())
</code></pre>

<p>or </p>

<pre><code>with open("file.txt") as f:
    qlist = [i.strip().split(",") for i in f.readlines()]
</code></pre>

python list file text