Here is the problem I am trying to solve.
For example there is this string
my_string = 'jan feb mar'
And I want to have sequentially generated items like this in a list.
It is always true that the words in a string are splittable with ' '
.
my_function(my_string)
output = ['jan', 'jan feb', 'jan mar', 'jan feb mar', 'feb','feb mar','mar']
What I tried is below and it is not what I want.
my_string = "jan feb mar"
words_list = my_string.split(' ')
words = [' '.join(words_list[i:i+n]) for i in range(len(words_list) - n+1)]
words.extend(input_list)
Please help me out here. Thanks.