|
|
|
|
|
by dozzie
2979 days ago
|
|
This is exactly why you need to take some algorithms and data structures
lecture. Who in their right mind would think that checking if a key is present
in a hash map takes O(n) time by generating a list of all keys and linear
search when extracting the value from under that key takes O(1)? |
|
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?