题解 | #遍历字典#
遍历字典
https://www.nowcoder.com/practice/0315639767824323a2cdb9ee3f998314
# operators_dict = {'<': 'less than', '==': 'equal'}
# print('Here is the original dict:')
# # 这里遍历的是keys,通过索引找到相应的value
# for x in sorted(operators_dict):
# print(f'Operator {x} means {operators_dict[x]}.')
# print(" ")
# operators_dict['>']='greater than'
# print("The dict was changed to:")
# for x in sorted(operators_dict):
# print(f'Operator {x} means {operators_dict[x]}.')
operators_dict = {'<': 'less than', '==': 'equal'}
print('Here is the original dict:')
# 这里遍历的是keys,通过索引找到相应的value
for x, v in sorted(operators_dict.items()):
print(f'Operator {x} means {v}.')
print(" ")
operators_dict['>']='greater than'
print("The dict was changed to:")
for x, v in sorted(operators_dict.items()):
print(f'Operator {x} means {v}.')
Two methods to traverse the list.
小天才公司福利 1199人发布
查看29道真题和解析