I want to save all word permutations that are in a sentence in to a list.
I want to use this for autocomplete.
For example:
s = "Stackoverflow is a platform"
When I split by a whitespace. I get [‘Stackoverflow’, ‘is’, ‘a’, ‘platform’] and use the list as suggestions.
It only worked if I type Stackoverflow but it wouldn’t suggest anything if I type Stackoverflow is
I want it to be saved as:
list = ['Stackoverflow', 'Stackoverflow is','Stackoverflow is a', 'Stackoverflow is a platform']
>Solution :
s = "Stackoverflow is a platform"
L = s.split(' ')
K = [' '.join(L[0:i]) for i in range(1,len(L)+1)]
print(K)