I have this:
def get_set(line, n=3):
words = line.split()
for i in range(len(words) - n):
yield (words[i], words[i+1], words[i+2])
for i in get_set('This is a test'):
print(i)
But as you can see in the yield
call, it's hard-coded to work with 3. How can I rewrite the yield
line to work with whatever number is passed via the n
kwarg?
(the code generators sets of each three consecutive words in a sentence, want it to generate whatever I pass as n
)