I have a book on Python which says:
in
is a very fast operation on sets:stopwords_list = ["a", "an"] + hundreds_of_other_words + ["yet", "you"] "zip" in stopwords_list # False, but have to check every element stopwords_set = set(stopwords_list) "zip" in stopwords_set # Very fast to check
I have two questions:
- Why is
in
faster on sets than on lists? - If the
in
operator really is faster on sets, then why don't the makers of Python just rewrite thein
method for lists to dox in set(list)
? Why can't the idea in this book just be made part of the language?