简体   繁体   English

什么是Java Collections Framework的Python等价物?

[英]What is/are the Python equivalent(s) to the Java Collections Framework?

The Java Collections Framework is like the C++ Standard Template Library: "a unified architecture for representing and manipulating collections (objects that group multiple elements into a single unit)." Java Collections Framework就像C ++标准模板库:“用于表示和操作集合的统一体系结构(将多个元素组合成一个单元的对象)。”

http://java.sun.com/docs/books/tutorial/collections/intro/index.html http://java.sun.com/docs/books/tutorial/collections/intro/index.html

As it turns out, the equivalent to the Java Collections Framework in Python is... Python. 事实证明,与Python中的Java Collections Framework相同的是...... Python。 All of the core collections featured in the Java Collections Framework are already present in core Python. Java Collections Framework中的所有核心集合都已存在于核心Python中。

Give it a try! 试试看! Sequences provide lists, queues, stacks, etc. Dictionaries are your hash-tables and maps. 序列提供列表,队列,堆栈等。字典是您的哈希表和映射。 Sets are present, etc. 集合存在等

One might consider Python a "higher" language than Java, because it natively provides all of these higher order abstract data types intrinsically. 人们可能会认为Python是一种比Java更“高”的语言,因为它本质上本质上提供了所有这些高阶抽象数据类型。 (It also supports Object Oriented, procedural, and functional programming methodologies.) (它还支持面向对象,程序和函数式编程方法。)

Other than the built-ins you might what to check out collections . 除了内置插件,您可以查看集合

>>> import collections
>>> dir(collections)
['Callable', 'Container', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping', 'MappingView', 'MutableMapping', 'MutableSequence', 'MutableSet', 'Sequence', 'Set', 'Sized', 'ValuesView', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_abcoll', '_iskeyword', '_itemgetter', '_sys', 'defaultdict', 'deque', 'namedtuple']
>>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM