Trying to append a dictionary in the list as an element


#1
....
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]

clark = {}
students.append(clark)
print students

Output
[lloyd,alice,tyler,{}]

This isn’t that I want, I want it to be like this

[lloyd,alice,tyler,clark]

Is it possible to do it like that?

CONTEXT:
Actually I was trying to write a function that takes user inputs of the dictionary name and all it’s sub values and then appends it to the main student list. This isn’t in the tutorial but I’m trying to write my own extra feature, any helo would be appreciated


#2

if you want to see names instead of dictionaries, then you want a string
alternatively a custom class where you override the string representation to show a name but otherwise behave like a dict


#3

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