I’m developing a dictionary kind of application using python. In my code, there is a list which consists of sorted set of strings. when a user give some text, I want to get all the string starting with the given string. In other words, I just want to suggest words while user is typing.
Example : If user typed the word “sub”, I want to take all the string from the list starting with the substring “sub”.
Can anyone give me an algorithm to do this? Thanks all.
Depending on the size of the list, you could just iterate through it and use the startswith() string function to get the result. If that’s too slow, a common way is to use a prefix tree.