Question about "4.for the record"


#1



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

I want to know that why the result in the console does not output in an order by name\homework\quizzes\tests?

Here is my result.
[88.0, 40.0, 94.0]
[75.0, 90.0]
Lloyd
[90.0, 97.0, 75.0, 92.0]
[82.0, 83.0, 91.0]
[89.0, 97.0]
Alice
[100.0, 92.0, 98.0, 100.0]
[0.0, 75.0, 78.0]
[100.0, 100.0]
Tyler
[0.0, 87.0, 75.0, 22.0]
None


lloyd = {
    "name": "Lloyd",
    "homework": [],
    "quizzes": [],
    "tests": []
}
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]
}

lloyd["homework"]=[90.0, 97.0, 75.0, 92.0]
lloyd["quizzes"]=[88.0, 40.0, 94.0]
lloyd["tests"]=[75.0, 90.0]

students=[lloyd,alice,tyler]

for s in students:
    for key in s:
        print s[key]


#2

Hi @coastharu,

Remember that when you iterate over a dictionary such as lloyd or alice, the output will not necessarily follow the sequence of the keys in the dictionary. So when you did this:

your console does not show the results in a particular order. If you wanted it to follow a particular order, you can consider something like:

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

Hope this helps :slight_smile:


#4

I get it, thank you.:grinning:


#5

welcome :slight_smile:


#7