Trying to be ambitious, any way this is possible?


#1




File "python", line 7
key = {'name':%s, 'homework':[], 'quizzes':[],'tests':[],} %s key
^
SyntaxError: invalid syntax


I was intending to add to all the dictionaries at once rather than writing out line by line, and reading the forum I see it is easier to go line by line, but... If I wanted to do it like this for the exercise, how would I put the name in the value associated with the name key and how to capitalise the first letter whilst adding it. Appreciate the help.


lloyd = {}
alice = {}
tyler = {}

students = {'lloyd': {},'alice' :{},'tyler':{}}
for key in students:
    key = {'name':%s, 'homework':[], 'quizzes':[],'tests':[]} %s key


#2

EDIT (January 5, 2017) : The code presented below is not recommended; it is being offered to the user only as a means of experimenting with Python concepts.

Hi, @textsolver25911 ,

As a means of practicing Python skills, you can add all the dictionaries at once, as you are attempting, as an alternative to writing them out individually. However, your observation that it is easier to create them separately is correct.

The following will work, but the technique that the instructions are promoting is quite clearer and less prone to developing bugs ...

lloyd = {"name": "Lloyd"}
alice = {"name": "Alice"}
tyler = {"name": "Tyler"}

students = [lloyd, alice, tyler]
keys = ["homework", "quizzes", "tests"]

for student in students:
    for key in keys:
        student[key] = []

Here is another technique that works, but again, the approach that the instructions specify is clearer and less likely to become buggy ...

# Create the students list first.
students = [
    {"name": "Lloyd",
     "homework": [90.0,97.0,75.0,92.0],
     "quizzes": [88.0,40.0,94.0],
     "tests": [75.0,90.0]
     },
    {"name": "Alice",
     "homework": [100.0, 92.0, 98.0, 100.0],
     "quizzes": [82.0, 83.0, 91.0],
     "tests": [89.0, 97.0]
     },
    {"name": "Tyler",
     "homework": [0.0, 87.0, 75.0, 22.0],
     "quizzes": [0.0, 75.0, 78.0],
     "tests": [100.0, 100.0]
     }
    ]
# Now, create the individual dictionary reference variables.
lloyd = students[0]
alice = students[1]
tyler = students[2]

#3

Thanks, I see how it is. Appreciate the help!


#4