Why can't I add a value to a dictionary with the .append?


#1

Hi
In the last exercise, I am asked to add a value (which contains a list of strings) to a dictionary. I tries to use .append but it doesn’t work. Instead I just have to define the list’s value to the dictionary. Why can’t I use the .append? Is it not working, because I didn’t clearly define the value “pocket”?


#2

list.append() is not applicable to dictionaries, only lists.

To append a dictionary, you simply assign a value to a key…

>>> my_dict = {}
>>> my_dict['city'] = "Edmonton"
>>> my_dict
{'city': 'Edmonton'}
>>> 

#3

got it, thanks! Now it is clear.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.