#compsci #python Dictionaries are mappings that are also mutable. ## Operations ### Basic Dictionaries are coded in curly braces in a manner like this: ```python D={'key1':'value1','key2':'value2'} ``` Since dictionaries are mutable, you can edit them just like lists: ```pyhon D={} D['test']='something' ``` We can index this dictionary by key to fetch and change the keys' associated values: ```python print(D['key1']) # value1 D['key1']='lololol' # key1 = lololol ``` ### Sorting To to impose an ordering on a dictionary's items: 1. use the **keys** method to make a [[Python Lists|list]] of the dictionary's keys 2. sort them using the **sort** method 3. use the for loop ```python D={'a':1,'b':2,'c':3} Ks=list(D.keys()) Ks.sort() for key in Ks: print(key,'=>',D[key]) ```