python – OrderedDict:也是有序的值?
发布时间:2020-11-18 06:32:50 所属栏目:Python 来源:互联网
导读:参见英文答案 Python dictionary: are keys() and values() always the same order?8个 collections.OrderedDict文档将OrderedDict描述为 a dict that remembers the order that keys were
参见英文答案 >
Python dictionary: are keys() and values() always the same order?8个
所以顺序 for k in dict: ... for k in dict.keys(): ... 是可以预测的. 但是,它没有说出价值观.如果我只需要按如下方式迭代值,结果是否也会遵循逐个插入的顺序? for v in dict.values(): ... CPython中的一些快速测试表明情况就是如此,但这可能只是当前实现的coinicidental(我没有测试任何其他). 解决方法是的,按键()和值()的列表按所有词组中的相应顺序排列,not just in ordered ones.(对于普通词典,顺序是任意的,但对于keys(),values()和items(),它是相同的任意顺序除非在此期间修改了字典.)(编辑:哈尔滨站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python – 来自Windows的OpenCV构建错误“RC对象”
- 解读Python中degrees()方法的使用
- Python 2与Python 3 – 过滤器行为的差异
- python – Sympy:在多项式中删除高阶项
- python – 将数字字符引用表示法转换为unicode字符串
- import pyttsx在python 2.7中工作,但不在python3中
- python – 大型Pandas Dataframe并行处理
- python – Flask:后台线程看到一个非空队列为空
- python – django auth用户截断电子邮件字段
- ImportError:没有模块名称’matplotlib’Python 3.3