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)
manpreet
Best Answer
2 years ago
I'm searching for 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 unique as in this example.
The first method I try is (3.8sec in my real code):
The second method I try is (2x faster:1.9sec on my real code):
Proposed methods from Stackoverflow user (2.74sec on my real code):
In my real code, the first method takes 3.81sec and the second method takes 1.88sec. It's a good improvement but:
I'm a beginner with Python/scripting and I want to know if a faster way exists to do the same things and save more processing time?
More specific explication for my application:
In the blender API I can access a list of particles:
From there, I can access a particle's location:
And for each particle I test if a neighbour exists by searching each particle location like so: