Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

save all word permutations that are in a sentence in to a list

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"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading