# -*- coding:utf-8 -*-
from random import randint
d = {x: randint(60, 100) for x in 'xyzabc'}
# 问题如下:
sorted(d)
# ['a', 'b', 'c', 'x', 'y', 'z']
# sorted()只是将字典中的键排了序
# 将字典转化成可迭代对象
iter(d)
# <dictionary-keyiterator object at 0x7f56eb4999f0>
list(iter(d))
# ['a', 'c', 'b', 'y', 'x', 'z']
# 转化成list对象,发现没有了键值
2-4根据字典中值的大小,对字典中的项排序
最新推荐文章于 2019-04-18 22:37:00 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交