-3

So I have a file ( user.txt ) containing this

James, 10, Orange 
Andrew, 16, Yellow 
Graham, 23, Pink

I want to make it so I can read the file into a nested list so I will have

print(user[0][1])
#10

I attempted:

with open("user.txt") as file:
    user = [line.split(", ") for line in file.readlines()]

print(user[0][1])

however I get 'IndexError: list index out of range'

Hope someone can help

R2D2
  • 1
  • 1
  • 3

1 Answers1

1
with open("file location") as file:
    user = [line.rstrip("\n").split(", ") for line in file]
Denziloe
  • 7,473
  • 3
  • 24
  • 34