0

I'm trying to add a third value to existing dictionary keys in Python. I'm sure this is probably easy, but I'm fairly new to coding so each way I've tried has thrown an error. Below is an example of what I tried which resulted in a syntax error. I also tried making the colon an equal sign but I got the message can't assign to a literal which I figure is due to the presence of two different = in the same line of code.

student = [
        { "name": "Kellie", "student_id": 12345},
        { "name": "James", "student_id": 39875},
        { "name": "Katie", "student_id": 24680},
        ]

student[0] = "lastName" : "Vee"
student[1] = "lastName" : "Tee"
student[2] = "lastName" : "Zee"
martineau
  • 119,623
  • 25
  • 170
  • 301
K.Vert
  • 1
  • 1
  • 1

1 Answers1

0

Try to add element like this:

student[0]["grade"] = "1"

It will add here: { "name": "Kellie", "student_id": 12345} new key "grade" and asign the value of 1.

monteua
  • 106
  • 1
  • 9