I just want to slice string from the beginning.As like I have a sentences:
"All the best wishes"
I want to get
"the best wishes" , "best wishes", "wishes".
Any solution please,Thanks!
use:
searchWords.extend([' '.join(words[i:]) for i in xrange(1, len(words))])
searchWords.extend([' '.join(words[:i]) for i in xrange(-1, len(words))])Eh, pythoners;]
You can always do it with simple loop and function:
def parts(s, fromstart=True):
sl, slp, idx = s.split(), [], 0 if fromstart else -1
while len(sl)>1:
sl.pop(idx)
slp.append(' '.join(sl))
return slp
s = 'All the best wishes'
parts(s) # -> ['the best wishes', 'best wishes', 'wishes']
parts(s,False) # -> ['All the best', 'All the', 'All']