From the student exercises on codecademy.com ….

There was this exercise:

The exercise was simple… update Lloyd’s homework, quizzes and test scores to be what they provided.

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

 

You can access the lloyd dictionary with lloyd[‘homework’] like so.  So to insert data into that list, we could do:

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

Doing so will set those empty lists in the lloyd dictionary.

Leave a Reply

Your email address will not be published. Required fields are marked *