I have one class have 2 variable members:
class A:
fullname = ""
email = ""
There is a list of A stored in memory, now I need to search against fullname or email, the search needs to support fuzzy search(assemble the SQL ‘like’ clause), eg) search “abc”, for “dabcd” it should match(if it can show the exact match first it will be better).
I think I should build index on ‘fullname’ and ’email’?
Please suggest, thanks!
EDIT: If I only need exact match, will two dictionaries with ‘fullname’ and ’email’ to be the key is the best choice? I see some articles says the fetching is O(1).
2nd EDIT: The ‘best’ I defined is for the search speed(best speed). As I think in python a reference will only be stored as the pointer into the dictionaries, so the space allocation should not be a problem. I have thousands of record.
If by “Best” you mean “best speed”, then yes.
That’s correct.
Two dictionaries would be fast.
If you want “like” clause behavior, it doesn’t matter. Most structures are equally slow. A dictionary will work, and will be reasonably fast. A list, however, will be about the same speed.