Issue with students list in "For the record"


#1



https://www.codecademy.com/en/courses/python-beginner-en-qzsCL/0/4?curriculum_id=4f89dab3d788890003000096


Hello, it tells me that I can't access the items constituting the students list with strings, I should use integers as an index instead. So the problem is the for-loop is not executed once. That doesn't make sense to me though, since the keys are obviously in string-format. What do I need to fix?


lloyd = {
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
alice = {
    "name": "Alice",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}

students = ["lloyd", "alice", "tyler"]

for item in students:
    print item["name"]
    print item["homework"]
    print item["quizzes"]
    print item["tests"]


#2

the problem is here:

students = ["lloyd", "alice", "tyler"]

this are just strings stored in a list. We should store the dictionaries in a list, so we can loop over them (otherwise we would have to write them all manually)


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.