I would like to store a lot of instances of some data in python. Each record has the following fields: username, address, salary etc...
The username should be unique. I do a lot of searches.
Currently I am using a list of dictionaries, but when I insert a new item I iterate the list and check the username of each dictionary, which is O(n). Searching is O(n) too. How could I achieve that there is an index on usernames, and make the search time O(logn)?
O(log n)is with binary searching, which suggests ordering your list alphabetically by username. If usernames are unique, why not just use an outer dictionary, though?