且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python集与列表

更新时间:2023-11-26 10:06:34

这取决于您打算如何使用它.

It depends on what you are intending to do with it.

在确定对象是否存在于集合中时,集合要快得多(如x in s所示),但是在遍历它们的内容时,集合要比列表慢.

Sets are significantly faster when it comes to determining if an object is present in the set (as in x in s), but are slower than lists when it comes to iterating over their contents.

您可以使用 timeit模块来了解哪种情况更适合您.

You can use the timeit module to see which is faster for your situation.