为什么没有有序的词典? [英] Why are there no ordered dictionaries?

查看:51
本文介绍了为什么没有有序的词典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个常见问题解答,但我敢问它,因为我还没有找到一个令人满意的答案:为什么没有订购

字典"至少在标准清单中?我一次又一次地错过了这个功能。
也许我的编程有点问题

风格,但我认为它通常很有用。


我完全赞同以下帖子,有人抱怨为什么所以

非常基本且有用的东西不属于标准库:
http://groups.google.com/group/comp=\"52d2f771a49857


有吗计划什么时候进入标准的lib?


- Christoph

This is probably a FAQ, but I dare to ask it nevertheless since I
haven''t found a satisfying answer yet: Why isn''t there an "ordered
dictionary" class at least in the standard list? Time and again I am
missing that feature. Maybe there is something wrong with my programming
style, but I rather think it is generally useful.

I fully agree with the following posting where somebody complains why so
very basic and useful things are not part of the standard library:
http://groups.google.com/group/comp....52d2f771a49857

Are there plans to get it into the standard lib sometime?

-- Christoph

推荐答案

Christoph Zwerschke< ci**@online.de>写道:
Christoph Zwerschke <ci**@online.de> wrote:
这可能是一个FAQ,但我敢问它,因为我还没有找到一个令人满意的答案:为什么没有订购 br />字典至少在标准清单中?


你收到的答案有哪些不满意?


一些可能的答案:本地字典非常快,部分是因为

实施不需要确保任何特定的订购。

订购钥匙不是正常情况,并且可以在
$ b时轻松完成需要$ b。


您问为什么不?而不是有人这样做了;如果

你问过后者的Python Cookbook,你可能会发现这样的东西




< URL:http ://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747>


有点陈旧,并且可以预先定义可子类化的原生类型,但是非常好

可维修。

一次又一次我错过了这个功能。也许我的编程风格有问题,但我认为它通常是有用的。


在什么情况下你发现自己需要一个保存其

关键订单的字典?你能提出一个可以通过

订购的dict改进的用例吗?

我完全赞同以下帖子,其中有人抱怨
为什么这么基本和有用的东西不是标准库的一部分:


就我而言,我认为标准

库没有Python的优点不会迅速改变。它允许许多竞争的

实现在每个人开始之前被动摇,取决于

其中任何一个。

是否有计划将其纳入某个时候标准的lib?
This is probably a FAQ, but I dare to ask it nevertheless since I
haven''t found a satisfying answer yet: Why isn''t there an "ordered
dictionary" class at least in the standard list?
What answers have you received that have not been satisfactory?

Some possible answers: The native dict is very fast, partly because
the implementation doesn''t need to ensure any particular ordering.
Ordering the keys isn''t the normal case, and can be done easily when
needed.

You asked "why not" rather than "has anyone done this anyway"; if
you asked the latter of the Python Cookbook, you might find something
like this:

<URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747>

A little old, and pre-dates subclassable native types, but quite
serviceable.
Time and again I am missing that feature. Maybe there is something
wrong with my programming style, but I rather think it is generally
useful.
In what cases do you find yourself needing a dict that preserves its
key order? Can you present a use case that would be improved by an
ordered dict?
I fully agree with the following posting where somebody complains
why so very basic and useful things are not part of the standard
library:
For my part, I consider it a virtue of Python that the standard
library doesn''t change rapidly. It allows many competing
implementations to be shaken out before everyone starts depending on
any one of them.
Are there plans to get it into the standard lib sometime?




在哪里可以找到答案:


< URL:http://www.python .org / peps / pep-0000.html>


在哪里更改答案:


< URL:http:// www .python.org / peps / pep-0001.html>


-

\你从互联网上学到的最重要的事情之一|

` \是那里没有''他们'。它只是一个非常多的|

_o__)''我们''。 - 道格拉斯亚当斯|

Ben Finney



Where to find an answer:

<URL:http://www.python.org/peps/pep-0000.html>

Where to change that answer:

<URL:http://www.python.org/peps/pep-0001.html>

--
\ "One of the most important things you learn from the internet |
`\ is that there is no ''them'' out there. It''s just an awful lot of |
_o__) ''us''." -- Douglas Adams |
Ben Finney


Christoph Zwerschke< ci ** @ online.de>写道:
Christoph Zwerschke <ci**@online.de> wrote:
这可能是一个FAQ,但我敢问它,因为我还没有找到一个令人满意的答案:为什么没有订购 br />字典至少在标准清单中?


你收到的答案有哪些不满意?


一些可能的答案:本地字典非常快,部分是因为

实施不需要确保任何特定的订购。

订购钥匙不是正常情况,并且可以在
$ b时轻松完成需要$ b。


您问为什么不?而不是有人这样做了;如果

你问过后者的Python Cookbook,你可能会发现这样的东西




< URL:http ://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747>


有点陈旧,并且可以预先定义可子类化的原生类型,但是非常好

可维修。

一次又一次我错过了这个功能。也许我的编程风格有问题,但我认为它通常是有用的。


在什么情况下你发现自己需要一个保存其

关键订单的字典?你能提出一个可以通过

订购的dict改进的用例吗?

我完全赞同以下帖子,其中有人抱怨
为什么这么基本和有用的东西不是标准库的一部分:


就我而言,我认为标准

库没有Python的优点不会迅速改变。它允许许多竞争的

实现在每个人开始之前被动摇,取决于

其中任何一个。

是否有计划将其纳入某个时候标准的lib?
This is probably a FAQ, but I dare to ask it nevertheless since I
haven''t found a satisfying answer yet: Why isn''t there an "ordered
dictionary" class at least in the standard list?
What answers have you received that have not been satisfactory?

Some possible answers: The native dict is very fast, partly because
the implementation doesn''t need to ensure any particular ordering.
Ordering the keys isn''t the normal case, and can be done easily when
needed.

You asked "why not" rather than "has anyone done this anyway"; if
you asked the latter of the Python Cookbook, you might find something
like this:

<URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747>

A little old, and pre-dates subclassable native types, but quite
serviceable.
Time and again I am missing that feature. Maybe there is something
wrong with my programming style, but I rather think it is generally
useful.
In what cases do you find yourself needing a dict that preserves its
key order? Can you present a use case that would be improved by an
ordered dict?
I fully agree with the following posting where somebody complains
why so very basic and useful things are not part of the standard
library:
For my part, I consider it a virtue of Python that the standard
library doesn''t change rapidly. It allows many competing
implementations to be shaken out before everyone starts depending on
any one of them.
Are there plans to get it into the standard lib sometime?




在哪里可以找到答案:


< URL:http://www.python .org / peps / pep-0000.html>


在哪里更改答案:


< URL:http:// www .python.org / peps / pep-0001.html>


-

\你从互联网上学到的最重要的事情之一|

` \是那里没有''他们'。它只是一个非常多的|

_o__)''我们''。 - 道格拉斯亚当斯|

Ben Finney



Where to find an answer:

<URL:http://www.python.org/peps/pep-0000.html>

Where to change that answer:

<URL:http://www.python.org/peps/pep-0001.html>

--
\ "One of the most important things you learn from the internet |
`\ is that there is no ''them'' out there. It''s just an awful lot of |
_o__) ''us''." -- Douglas Adams |
Ben Finney




Uzytkownik" Christoph Zwerschke" < CI ** @ online.de> napisal w wiadomosci

新闻:dl ********** @ online.de ...

Uzytkownik "Christoph Zwerschke" <ci**@online.de> napisal w wiadomosci
news:dl**********@online.de...
这可能是常见问题,但我敢问然而,因为我还没有找到令人满意的答案:为什么没有有序的词典?至少在标准清单中?我一次又一次地错过了那个功能。也许我的编程风格有问题,但我认为它通常很有用。

我完全赞同以下帖子,有人抱怨为什么这么说非常基本和有用的东西不是标准库的一部分:
http://groups.google.com/group/comp....52d2f771a49857

是否有计划在某个时候将其纳入标准库?

- Christoph
This is probably a FAQ, but I dare to ask it nevertheless since I
haven''t found a satisfying answer yet: Why isn''t there an "ordered
dictionary" class at least in the standard list? Time and again I am
missing that feature. Maybe there is something wrong with my programming
style, but I rather think it is generally useful.

I fully agree with the following posting where somebody complains why so
very basic and useful things are not part of the standard library:
http://groups.google.com/group/comp....52d2f771a49857

Are there plans to get it into the standard lib sometime?

-- Christoph




i我不确定订购字典的目的是什么?
python,你可以提供任何例子吗?


i使用结构:

for x in sorted(d.keys())


欢呼,


przemek



i am not sure what is the purpose of having ordered dictionaries built in
python, could u provide any examples?

i use a contruction:
for x in sorted(d.keys())

cheers,

przemek


这篇关于为什么没有有序的词典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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