# Copying and modifying a dictionary
search_key = "red"
my_dict = {"red": 1, "blue": 2, "green": 3}
keys_copy = list(my_dict.keys()) # copy original dict keys
for key in keys_copy: # loop over the copy
if key == search_key:
my_dict["green"] = 4 # modify the original
print(my_dict)
# Copying and modifying a list
my_list = [1, 2, 3]
list_copy = list(my_list)
for number in list_copy:
print(number)
if number == 2:
my_list.insert(0, 4) # okay
print(my_list)
# copy and modifying a set
my_set = {"red", "blue", "green"}
set_copy = set(my_set)
for colour in set_copy:
if colour == search_key:
my_set.add("yellow")
print(my_set)