题解 | 遍历字典
# 创建字典 operators_dict = {"<": "less than", "==": "equal"} # 打印原始字典信息 print("Here is the original dict:") for key in sorted(operators_dict): print(f"Operator {key} means {operators_dict[key]}.") # 增加新的键值对 operators_dict[">"] = "greater than" # 打印分隔行 print() # 打印更改后的字典信息 print("The dict was changed to:") for key in sorted(operators_dict): print(f"Operator {key} means {operators_dict[key]}.")