I've declared some dicts that contain keys for each NFL team and an object related to them.
Now I'm trying to modify those dicts in order to have a key called 'teams' where I would put the previous values of the dict, and 5 new keys named 2018 to 2022
tmp = ['Packers', 'Vikings', 'Lions', 'Bears']
NFC_North = {name: team(name=name) for name in tmp}
tmp = ['Buccaneers', 'Saints', 'Panthers', 'Falcons']
NFC_South = {name: team(name=name) for name in tmp}
tmp = ['Cowboys', 'Giants', 'Eagles', 'Commanders']
NFC_East = {name: team(name=name) for name in tmp}
tmp = ['Rams', 'Cardinals', 'Seahawks', '49ers']
NFC_West = {name: team(name=name) for name in tmp}
NFC = [NFC_North, NFC_South, NFC_East, NFC_West]
I've tried implementing a for loop that iterates over every team and does what I described before. But when I check if the dict was modified, it reimained the same
print(NFC[0])
for i in NFC:
i = {
'teams': i,
'2022': 0,
'2021': 0,
'2020': 0,
'2019': 0,
'2018': 0
}
print(NFC_North, i)
I checked the id's and I realized that items[i](suppose i = 0) is not the same object as NFC_North. Even though NFC_North is actually the first element in the NFC list
My code works as expected inside the loop, but I can't modify the actual element I want to modify and I don't know why it doesen't get modified and how can I do to modify it
I'm new to programming and this is my first time posting here, hope I wrote it in the right way. Thanks to you all in advance
Edit: Many of you are recommending me to do the following:
for i in range(len(NFC)):
NFC[i] = {
'teams': NFC[i],
'2022': 0,
'2021': 0,
'2020': 0,
'2019': 0,
'2018': 0
}
But the output remains the same. Correct me if I'm doing something wrong but I think this is the solution everybody is redirecting me towards, it's behaving just the same