基本上我想知道这东西在引擎盖下是怎么工作的。我试图创建一个元组列表[(),(),…],每个元组都有两个值,qst wuld是键,second是值。但这不是一个真正的字典,而且还有性能问题(我是指读/写/删除操作)。在
那么我应该如何编写一个类MyOrderedDict
,它(可能)将扩展默认的dict
类。在
任何提示或资源将不胜感激。在
附言:我们在Django也有类似的功能。SortedDict
from django.utils.datastructures import SortedDict
它们是相同的还是遵循相同的实施方法?在
Help on class SortedDict in module django.utils.datastructures:
class SortedDict(__builtin__.dict)
| A dictionary that keeps its keys in the order in which they're inserted.
|
| Method resolution order:
| SortedDict
| __builtin__.dict
| __builtin__.object
|
| Methods defined here:
这个班将管理一本字典和一个列表。在幕后,对于每个标准dict操作,它将同时使用:
要通过键获取值,作为标准字典:
^{pr2}$要按输入顺序m获取值:
^{3}$添加键,值:
等等
你可以看看source in Python 2。它似乎是用C为python3实现的。在
相关问题 更多 >
编程相关推荐