kept getting this error: for name, home in reader: ValueError: too many values to unpack (expected 2)

Viewed 29

kept getting

ValueError: too many values to unpack(expected 2)

here's the csv file:

adebayo,sagamu sagamu, olomu 
yusuf,sagamu sagamu
kayode,sagamu sagamu
gbolahan,ilorin ilorin
abiodun,ilorin ilorin
import csv
students = []
with open("names.csv") as file:
    reader = csv.reader(file)
    for name, home in reader:
        students.append({"name": name, "home": home})

for student in sorted(students, key=lambda  student: student["name"]):
    print(f"{student['name']} is from {student['home']}")
1 Answers

You have to make your first line in csv file like this for it to work

adebayo,"sagamu sagamu, olomu"

Related