The comparison operators in and not in check whether a value occurs in a sequence data type (a list, tuple, or string), a dict, or a set.
The following example checks for the text 'fox' in a set:
>>> data = set(["the", "quick", "brown", "fox"])
Call out the hounds!
Tip If your program works with lots of data, it's a Good Idea to use dicts or sets to store the data. Searching dicts and sets is faster than searching sequences.
Was this article helpful?