Answer the question
In order to leave comments, you need to log in
What is the fastest object to brute force search in Python?
I create a database for example fruits - 'Apple', 'Orange', 'Mandarin' so that later I can check if there is a new fruit in this list. Fruit many thousands and many thousands of times I will check by enumeration.
If I correctly understood the naguglenoe - the fastest way is to check the dictionary, because the hash table.
Can I create a dictionary of keys without values so that I can then check 'Watermelon' in the dict?
If not, I can set the keys to zero. And then output the keys to check in
listkeys = dict.keys()
and check Watermelon' in listkeys
Wouldn't that lose the performance advantage of hash table lookups?
In short - you need an object with fruit for the fastest enumeration. )
Answer the question
In order to leave comments, you need to log in
fruits = set()
fruits.add("Apple")
fruits.add("Apple") # Ничего не произойдёт
fruits.add("Pineapple")
assert "Apple" in fruits
assert "Watermelon" not in fruits
print(fruits)
fruits.remove("Apple")
assert "Apple" not in fruits
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question