For The Record


#1



4. For the record


I figured out the code, however I just want to get some feedback to if I am reading it(in English) correctly.


I am reading this as:
1. created dictionaries with lists (grades)
2. created the list (students) to call the dictionaries from?
3. used "for" function to pull dictionaries and its lists from the (condensed) students list.

Just want to be able to explain what the code is doing properly.


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 student in students:
    print student['name']
    print student['homework']
    print student['quizzes']
    print student['tests']


#2

Basically, yes. To expand a bit, the for item creates a loop which iterates through an item (string, list, dictionary, array, etc) until it has a reason not to; ie the end of the item, a return statement, or any other number of things that signal a stopping point.


#3

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