Using the standard syntax that Python supplies to check if an element is in a list:
if someElement in someList:
What is actually being executed here? Is Python looping through every index and checking for equality, or is something more sophisticated being implemented?
The program I am writing is running extremely slowly. No math is being performed, but it relies heavily on checking to see if items exist in long lists. Is there a more rapid solution?
SOLVED: Checking if an element is in a list is the same as looping through every item and checking for equality. However, checking for an item in a set is significantly faster since the items are hashed.
Even if the items in your list are unhashable (in my case, other lists), it is still worth it to convert to a string, store in a set, and convert back when needed. At first, I thought this was bulky and would decrease performance. However, it literally allowed my program to complete in a matter of minutes when it would have taken days previously.
Don't underestimate the speed of checking items in a set.