为什么Python的标准库中没有排序的容器? [英] Why are there no sorted containers in Python's standard libraries?

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

问题描述

是否有Python设计决策(PEP)阻止将排序后的容器添加到Python?

Is there a Python design decision (PEP) that precludes a sorted container from being added to Python?

(OrderedDict不是已排序的容器,因为它是按插入顺序排序的.)

(OrderedDict is not a sorted container since it is ordered by insertion order.)

推荐答案

这是Guido的一项有意识的设计决定(他甚至不愿意添加collections模块).他的目标是在选择应用程序的数据类型时保留一种显而易见的方式".

It's a conscious design decision on Guido's part (he was even somewhat reluctant regarding the addition of the collections module). His goal is to preserve "one obvious way to do it" when it comes to the selection of data types for applications.

基本概念是,如果用户足够复杂,以至于不能意识到内置类型不是解决其问题的正确解决方案,那么他们还可以找到合适的第三方库.

The basic concept is that if a user is sophisticated enough to realise that the builtin types aren't the right solution for their problem, then they're also up to the task of finding an appropriate third party library.

鉴于list + sorting,list + heapq和list + bisect涵盖了许多用例,这些用例原本依赖于固有排序的数据结构,并且存在诸如blist之类的包,因此没有很大的动力来添加更多复杂性.这个空间到标准库.

Given that list+sorting, list+heapq and list+bisect cover many of the use cases that would otherwise rely on inherently sorted data structures, and packages like blist exist, there isn't a huge drive to add more complexity in this space to the standard library.

在某些方面,这类似于标准库中没有多维数组的事实,而是将该任务割让给了NumPy员工.

In some ways, it is similar to the fact that there's no multi-dimensional array in the standard library, instead ceding that task to the NumPy folks.

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

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