Python equivalent for C++ STL vector/list containers

前端 未结 4 651
小鲜肉
小鲜肉 2020-12-29 06:29

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.

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 06:39

    Have a look at Python's datastructures page. Here's a rough translation:

    1. () => boost::Tuple (with one important distinction, you can't reassign values in a Python tuple)
    2. [] => std::vector (as the comments have aluded towards, lacks memory characteristics associated with vectors)
    3. [] => std::list
    4. {} => tr1::unordered_map or boost::unordered_map (essentially a hash table)
    5. set() => std::set

提交回复
热议问题