Fastest way to search a list in python

后端 未结 4 2288
北荒
北荒 2020-11-27 18:17

When you do something like \"test\" in a where a is a list does python do a sequential search on the list or does it create a hash table representa

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 18:44

    I think it would be better to go with the set implementation. I know for a fact that sets have O(1) lookup time. I think lists take O(n) lookup time. But even if lists are also O(1) lookup, you lose nothing with switching to sets.

    Further, sets don't allow duplicate values. This will make your program slightly more memory efficient as well

提交回复
热议问题