# # Python dict basic # person_1 = { "name": "Jane", "dob": "12/08/1997", "city": "Houston" } print(f"person_1: {person_1}") print(f"id(person_1): {id(person_1)}") person_1['school'] = 'uhcl' print(f"person_1 after 'person_1['school'] = 'uhcl'': {person_1}") print("dicts are mutable.") print(f"id(person_1): {id(person_1)}") print(""" # keys are unique. person_2 = { "name": "Jane", "name": "Johnson", "dob": "12/08/1997", "city": "Houston" } """) # keys are unique. person_2 = { "name": "Jane", "name": "Johnson", "dob": "12/08/1997", "city": "Houston" } print(f"person_2: {person_2}") def hello(): print("hello") def bye(): print("bye") print(""" # keys can be any mutable. dict_1 = { hello: 1, bye: 2, "hello": 3, 4: 4 } """) # keys can be any immutable. dict_1 = { hello: 1, bye: 2, "hello": 3, 4: 4 } print(f"dict_1: {dict_1}") print(f"dict_1[hello]: {dict_1[hello]}") print(f"dict_1['hello']: {dict_1['hello']}") print(f"dict_1[4]: {dict_1[4]}") # Keys cannot be mutable. print(""" # Keys cannot be mutable. list_1 = [1,2,3] dict_2 = { "hey": 1, list_1: 2 } Traceback (most recent call last): File "...", line 63, in dict_2 = { TypeError: unhashable type: 'list' """) print(""" # values can be mutable. list_1 = [1,2,3] dict_2 = { "hey": 1, "ho": list_1 } """) # values can be mutable. list_1 = [1,2,3] dict_2 = { "hey": 1, "ho": list_1 } print(f"list_1: {list_1}") print(f"dict_2: {dict_2}") # list_1.append(4) print("After 'list.append(4)':") print(f" list_1: {list_1}") print(f" dict_2: {dict_2}") dict_2['ho'].append(7) print("After 'dict_2['ho'].append(7):") print(f" list_1: {list_1}") print(f" dict_2: {dict_2}")