I need to create a matrix from a .txt file, the proble I'm having is that the .txt file has a LOT of information (maybe no that much, but I'm new on programming so I have problems dealing with it)... The file has:
- Client number
- Name
- Last name
- Age
- Single or married (S or M)
- Sex (M or F)
- Favourite animal
like this:
1 James Gordon 35 M M Dog
...
75 Julius Harrison 48 S M Cat
I managed to read the file and create a list for each one of the persons, but also it's needed to calculate the average of age, sex... I don't know how to separate each one of the elements so I can do the math. Here's the code so far.
infile=open("db.txt","r")
list=infile.read()
matrix=[]
raw = []
with open('db.txt','r') as f:
for line in f:
raw.append(line.split())