1 输出dict的value
代码:
test_dict = {"3":"happy", "5":"sad", "2":16, "10":"smile"}
for value in test_dict.values():
print(value)
输出:
2 输出dict的key
代码:
test_dict = {"3":"happy", "5":"sad", "2":16, "10":"smile"}
for key in test_dict.keys():
print(key)
输出:
3 按照key排序
代码:
test_dict = {"3":"happy", "5":"sad", "2":16, "10":"smile"}
test_dict = sorted(test_dict.items(), key=lambda k: int(k[0]))
print(test_dict)
输出: