|
|
|
|
|
by ilhicas
2979 days ago
|
|
Hello, I've had Data Structures, while on BSc and implemented by hand hashmaps.. If you read the post you would understand the doubt. Try the following: a = [i for in range(10000)]
if 9999 in a:
print('yay I just looped over an entire array') however: a = {i:i for in range(10000)}
if 9999 in a:
print('yay I found a key in linear time') Now, You might be an expert in Data Structures, but what makes you implicitly know how the 'IN' behaves in python, and that it won't convert to the keys() method of the dict to get a list with the same behaviour as in a list? |
|
Because it would be the dumb way to do it. You have a lookup procedure to extract a value from a hash. A procedure to check if the key is present in the hash will look exactly the same, barring the value being returned.
Libraries usually work the same way as you would write yourself if you were trained in the task, so it's easy to guess.