Put it together. I don't get it


#1


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


So I even tried printing the student list and it definitely is included so I'm not sure why the error message says,
"Oops, try again. It looks like Lloyd is not in the students list." I also tried capitalizing names. No dice

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"]


#2

Remove the quotes. These are dictionary identifiers, not strings..


#3

Thank you. So they were wanting me to make a list of the dictionaries, not a list of names, correct?


#4

Correct, a list of variable names that point to all the dictionaries.

In a loop,

for student in students:

student is a temporary name, assigned individually...

student => [
    lloyd
    alice
    tyler
] in students

When student is lloyd, it will be the lloyd dictionary that is accessed.


#5

That makes a lot more sense. I wasn't sure why they were asking me to make the list in the first place.


#6

Think of the list as an index of local dict objects. Since we wrote the dictionaries, we know what should be in the list. A program would not be able to see these objects without that list. It would need to call a built in function, such as locals() (not taught in this course so don't be segued, please).

It would be a tedious job to decipher the dictionary that function generates, not to mention messy. Better we tell our program where the objects are, and save a lot of trouble. If we dynamically add more objects, we have that list to tie them to, if nothing else.


#7

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