def stack_ov_test():
my_set = set([1, 2, 1, 2, 3, 4, 3, 2, 3])
my_dictionary = dict.fromkeys(my_set, [])
my_dictionary[1].append(0)
print(my_dictionary) # {1: [0], 2: [0], 3: [0], 4: [0]}
I think the code above is pretty much self-explanatory, and this is why this is bothering me that much. I simply want to create a dictionary out of a set / list and then add gradually data to each list of the keys. When referencing the list that I want to append to, all of the lists in the dictionary are being modified. Can somebody please explain me what I am missing? Thank you very much!
Small edit:
When I create the dictionary manually, everything works as usual:
def stack_ov_test():
my_dictionary = {1: [], 2: [], 3: []}
my_dictionary[1].append(0)
print(my_dictionary) # {1: [0], 2: [], 3: []}