I have a file containing:
name: Sam
placing: 2
quote: I'll win.name: Jamie
placing: 1
quote: Be the best.
and I want to read the file through python and append specific contents into a list. I want my first list to contain:
rank = [['Sam', 2],['Jamie', 1]]
and second list to contain:
quo = ['I'll win','Be the best']
first off, i start reading the file by:
def read_file():filename = open("player.txt","r")playerFile = filenameplayer = [] #first listquo = [] #second listfor line in playerFile: #going through each line line = line.strip().split(':') #strip new line print(line) #checking purposeplayer.append(line[1]) #index out of rangeplayer.append(line[2])quo.append(line[3])
I'm getting an index out of range in the first append. I have split by ':' but I can't seem to access it.