I recently asked a question about converting list of values from txt file to dictionary list. You can see it from the link here: See my question here
P883, Michael Smith, 1991
L672, Jane Collins, 1992
(added)
(empty line here)
L322, Randy Green, 1992
H732, Justin Wood, 1995(/added)
^key ^name ^year of birth
def load(filename): students = {}infile = open(filename) for line in infile: line = line.strip() parts = [p.strip() for p in line.split(",")] students[parts[0]] = (parts[1], parts[2]) return students
Check for empty lines inside your for-loop and skip them:
for line in infile:
line = line.strip()
if not line:
continue
parts = [p.strip() for p in line.split(",")]
students[parts[0]] = (parts[1], parts[2])