Converting File Data to Lists
<p>I have a file on sample employee data.  The first line is the name, the second line is the salary, the third line is life insurance election (Y/N), the fourth line is health insurance election (PPOI, PPOF, None), and it repeats.  A snippet of the file is below:</p>

<pre><code>Joffrey Baratheon
190922
Y
PPOI
Gregor Clegane
47226
Y
PPOI
Khal Drogo
133594
N
PPOI
Hodor
162581
Y
PPOF
Cersei Lannister
163985
N
PPOI
Tyrion Lannister
109253
N
PPOF
Jorah Mormont
61078
Y
None
Jon Snow
123222
N
None
</code></pre>

<p>How can I take this file data and extract each data type (name, salary, life insurance, health insurance) into four separate lists?<br>
 Currently, my code is creating a multidimensional list by employee, but I ultimately want four separate lists.  My current code is below:</p>

<pre><code>def fileread(text):
    in_file = open(text, "r")
    permlist = []
    x = 1
    templist = []
    for line in in_file:
        line = line.strip()
        templist.append(line)
        if x == 4:
            permlist.append(templist)
            templist = []
            x = 1
        else:
            x+=1
    return (permlist)
def main ():
    EmpData = fileread("EmployeeData.txt")
    index = 0
    print (EmpData[index])
</code></pre>

<p>Count the total lines, divide by four get number of people to add to the lists. </p>

<pre><code>i = 0
while i &lt; num_of_people:
    for a in range(0, num_of_people+1):
        namelist.append(i)
        i += 1
        salarylist.append(i)
        i +=1
        ...
</code></pre>

<p>Be careful splitting the data like this. Its easy to get confused.
You might be better off storing this data into a database.</p>

python list python-3.x