Given a search string input, I'd like to break it up into a group of possible matching groups. For consecutive terms though, such as for new search
, I would like to keep the original spacing.
Is there a library such as itertools
that can give all the consecutive combinations of words, for example:
INPUT ==> "new search words"
OUTPUT ==> ['new', 'search', 'words', 'new search', 'new search words', 'search words']
Note that I'm not looking to get a combination of all possible letters. For example:
>>> list(itertools.combinations(s, 1))
[('O',), ('n',), ('c',), ('e',), (' ',), ('u',), ('p',), ('o',), ('n',), (' ',), ('a',), (' ',), ('t',), ('i',), ('m',), ('e',), (' ',), ('i',), ('n',), (' ',), ('t',), ('h',), ('e',), (' ',), ('w',), ('e',), ('s',), ('t',), (' ',), ('U',), ('S',)]
I'm only looking for the possible word combinations, of which there are 6 (3!).