Skip to content
Advertisement

Fastest way to check if a value exists in a list

What is the fastest way to check if a value exists in a very large list?

Advertisement

Answer

7 in a

Clearest and fastest way to do it.

You can also consider using a set, but constructing that set from your list may take more time than faster membership testing will save. The only way to be certain is to benchmark well. (this also depends on what operations you require)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement