i tried to create a for loop that can change the value of dictionary 'title'. The new value will be then appended to the b list. So there will be 5 dict in b list with different 'title' value. This is my code.
dictionary = {'title': 'hello', 'black': 'white', 'yellow':'green'}
b = []
for a in range(5):
dictionary['title'] = str(a)
b.append(dictionary)
print b
The result is:
[{'black': 'white', 'yellow': 'green', 'title': '4'}, {'black': 'white', 'yellow': 'green', 'title': '4'}, {'black': 'white', 'yellow': 'green', 'title': '4'}, {'black': 'white', 'yellow': 'green', 'title': '4'}, {'black': 'white', 'yellow': 'green', 'title': '4'}]
[Finished in 0.136s]
Why all of the 'title' have the same value? How can I get a different number for each dicts appended to the list. Thanks
print binside the loop, You will understand everything.