I have a book on Python which says:
inis 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
infaster on sets than on lists? - If the
inoperator really is faster on sets, then why don't the makers of Python just rewrite theinmethod for lists to dox in set(list)? Why can't the idea in this book just be made part of the language?