How to add to the value of a dictionary (and not to update it) in a loop in Python

This is my code:

diction = {}

for i in range (5):
    key = "key"
    diction[key] = {str(i)}
print (diction)

The printed result, obviously, would be this: `{'key': {'4'}}.

How can I change the code so I can have this as the output:

{'key': {'0','1','2','3','4'}}

Read more here:

Content Attribution

This content was originally published by kepar48105 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: