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

Deadly 提交于 2021-02-18 07:22:47

问题


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)."

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


回答1:


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']
>>>



回答2:


As it turns out, the equivalent to the Java Collections Framework in Python is... Python. All of the core collections featured in the Java Collections Framework are already present in core 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. (It also supports Object Oriented, procedural, and functional programming methodologies.)



来源:https://stackoverflow.com/questions/2047220/what-is-are-the-python-equivalents-to-the-java-collections-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!