I have one dictionary:
dog = {'color': 'black'}
I created 3 similar dogs inside one list:
dogs = []
dog = {'color': 'black'}
for num in range(3):
dogs.append(dog)
When I try to modify first dog of my dogs list:
dogs[0]['color'] = 'white'
It retrieves me whole list been modified:
[{'color': 'white'}, {'color': 'white'}, {'color': 'white'}]
But when I declare my dog dictionary inside for loop and try to change single dog dictionary:
for num in range(3):
dog = {'color': 'black'}
dogs.append (dog)
dogs[0]['color'] = 'white'
I get the desired output:
[{'color': 'white'}, {'color': 'black'}, {'color': 'black'}]