做http://stardict.sourceforge.net/Dictionaries.php下载preserve迭代顺序,如果他们不被修改? [英] Do dicts preserve iteration order if they are not modified?

查看:99
本文介绍了做http://stardict.sourceforge.net/Dictionaries.php下载preserve迭代顺序,如果他们不被修改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有Python中的字典,我通过它遍历一次,然后再后来,是保证是$ P $迭代顺序pserved因为我没有插入,删除或更新中的所有项目字典? (不过,我可能会做的查找窗口)。

If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).

推荐答案

下面是 dict.items()文档说:

dict.items()返回(键,值)对字典的列表的副本。

dict.items() return a copy of the dictionary’s list of (key, value) pairs.

如果产品(),键(),值(),iteritems(),出iterkeys(),和itervalues​​()称为中间没有修改到词典中,列出了将直接对应

If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond.

我认为这是合理的假设,项目顺序不会改变,如果你要做的就是迭代。

I think it's reasonable to assume that item ordering won't change if all you do is iteration.

这篇关于做http://stardict.sourceforge.net/Dictionaries.php下载preserve迭代顺序,如果他们不被修改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆