Fastest way to check if a value exists in a list

后端 未结 12 2243
猫巷女王i
猫巷女王i 2020-11-22 00:18

What is the fastest way to know if a value exists in a list (a list with millions of values in it) and what its index is?

I know that all values in the list are uniqu

12条回答
  •  滥情空心
    2020-11-22 00:33

    def check_availability(element, collection: iter):
        return element in collection
    

    Usage

    check_availability('a', [1,2,3,4,'a','b','c'])
    

    I believe this is the fastest way to know if a chosen value is in an array.

提交回复
热议问题