C++ STL 向量/列表容器的 Python 等效项

2022-01-24 00:00:00 python list containers vector c++

Is there something similar in Python that I would use for a container that's like a vector and a list?

Any links would be helpful too.

解决方案

You can use the inbuilt list - underlying implementation is similar to C++ vector. Although some things differ - for example, you can put objects of different type in one and the same list.

http://effbot.org/zone/python-list.htm

N.B.: Please keep in mind that vector and list are two very different data structures. List are heterogeneous, i.e. can store different object types, while C++ vectors are homogeneous. The data in vectors is stored in linear arrangement whereas in list is a collection of references to the type and the memory address of the variables.

相关文章