I am facing a really simple and strange problem with Python.
I have a dict with several keys, that contain empty lists. I want to append/extend the content of lists of specific keys. The code I therefore think of looks like this
d = dict.fromkeys(['A','B','C'],[])
d['A'].append('Hello')
However, the result is not what I expect. The value of each key is a list containing one element: 'Hello'
>>> d
{'A': ['Hello'], 'C': ['Hello'], 'B': ['Hello']}
If I try what follows, it results in the same thing
d.get('A').append('Bye')
What operations I have to do obtain this?
>>> d
{'A': ['Hello'], 'C': [], 'B': []}
Can someone explains what goes wrong with my syntax?