题解 | #遍历字典#

遍历字典

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.

全部评论

相关推荐

最近拿到了正浩的提前批offer感觉自己的实力得到了肯定,也给了我更多底气
搞机墨镜猫:正浩提前批官网好像就只有电力电子软硬件,哥们投的是这两个岗位吗
26届校招投递进展
点赞 评论 收藏
分享
06-07 00:00
已编辑
腾讯_后端开发
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务