TAGS :Viewed: 4 - Published at: a few seconds ago

[ Python : parse string to sub string for searching ]

My web site run on gae, I want to implement a input-tag-box like tags input box in SO, but search on gae required user enter whole word for match.
Example hello world required user enter world or hello for result hello world and I want to when user enter some word like he or hel then result hello world.

I looking for a function for parse a string into multi sub string (implemented in python)

Ex: hello world --> he hel hell hello wor worl world.

Any other solution are welcome.


Answer 1

Use list comprehension and slicing:

>>> strs= "Hello world"
>>> [y for x in strs.split() for y in (x[:i] for i in  xrange(2,len(x)+1)) ]
['He', 'Hel', 'Hell', 'Hello', 'wo', 'wor', 'worl', 'world']