I have a piece of code where I’m trying to replace an item in a list which is in a dictionary. The code runs through the various tuples in the list and compares them, but doesn’t replace it.
for courses in students[names]: if courses[0] == course[0]: if course[1] > courses[1]: students[name[i]] = course
The dictionary is students, name is the key for the dictionary, i is which index in the list I want to replace and course is the tuple being replaced.
When I run the program instead of replacing the tuple at the location it creates a new key in the dictionary which is the letter in the location i of the string name. I also tried this version but it gets the same result:
students[names[i]] = course
DasBlayum is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.