I'm having an issue when I try to assign a value to a specific dictionary stored in a list of dictionaries is updated in every single dictionary in the list. I am trying to track project completion steps by year, using the index of the list as the year of the project (except with 0=year 1, etc)
The list is created like so:
results = [{'status':{'reports': False, 'collection': False, 'workshops':False}, 'dates':{'reports':'', 'collection':'','workshops':''}}] * years
Where years is the number of project years passed in to the function.
I end up iterating over a dictionary of milestones looking for the completion milestones like this:
for milestone in data:
if data['name'] == 'report completion':
if data['completed'] == True:
year = determineYear(x, y) #Pass some info from the milestone to determine which year of the project
results[year]['status']['reports'] = True
results[year]['dates']['reports'] = data['date']
The indenting didn't come through correctly, but I think you get the gist.
Everything seems to work correctly. The index(year)
is being calculated correctly, there's no extra looping or anything, but the list ends up looking like this:
[{'status': {'collection': False, 'workshops': False, 'reports': True}, 'dates': {'collection': '', 'workshops': '', 'reports': '03/10/2016'}},
{'status': {'collection': False, 'workshops': False, 'reports': True}, 'dates': {'collection': '', 'workshops': '', 'reports': '03/10/2016'}},
{'status': {'collection': False, 'workshops': False, 'reports': True}, 'dates': {'collection': '', 'workshops': '', 'reports': '03/10/2016'}}]
So the data is being stored in every dictionary in the list. This is the first time I've tried a setup like this, so I may be missing something.