Fastest way to search a list in python

Also note that the list of values I’ll have won’t have duplicate data and I don’t actually care about the order it’s in; I just need to be able to check for the existence of a value.

Don’t use a list, use a set() instead. It has exactly the properties you want, including a blazing fast in test.

I’ve seen speedups of 20x and higher in places (mostly heavy number crunching) where one list was changed for a set.

Leave a Comment