For example I have a dictionary:
dictionary = {'dog' : 'bark', 'cat' : 'kitten'}
And I want to add another value 'woof' to the key 'dog' so that I get:
{'dog': ['bark','woof'], 'cat' : 'kitten'}
And then add another value 'speak' to the key 'dog' so that I get:
{'dog': ['bark','woof', 'speak'], 'cat' : 'kitten'}
etc.
Any help is appreciated.
['dog']to see if its value is already a list (we know from your example that it's not, but it really doesn't hurt to double-check). You can do this withisinstance.if not isinstance(dictionary['dog'], list):