HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonCritical

Fastest way to check if a value exists in a list

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
listvalueexistswayfastestcheck

Problem

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

Solution

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)

Context

Stack Overflow Q#7571635, score: 2208

Revisions (0)

No revisions yet.