Declare dictionary in List


#1

Hello All. How to declare dictionary in a list? Please help

"""
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 = [llyod{},alice{},tyler{}]

"""


#2

^, use backticks to make indent as show in the topic i linked to above

You have a dictionary called alice, so you can just store alice in the list:

aList = [alice]

from a technical point of view you don't declare dictionary's in the list, you store a reference to the dictionary in the list.


#3

Thanks stetim. I did some silly mistake.(instead of lloyd i wrote llyod)


#4

programming languages are pretty unforgiving in this matter. lloyd and llyod would be considered two different variables.

Issue resolved?


#5

Yes stetim. It has been resolved. Thanks


#6