Generate a list of strings with a sliding window using itertools, yield, and iter() in Python 2.7.1?
I'm trying to generate a sliding window function in Python. I figured out how to do it but not all inside the function. itertools, yield, and iter() are entirely new to me. i want to input a='abcdefg' b=window(a,3) print b ['abc','bcd','cde','def','efg'] the way i got it work was def window(fseq, window_size=5): import itertools tentative=[] final=[] iteration=iter(fseq) value=tuple(itertools.islice(iteration,window_size)) if len(value) == window_size: yield value for element in iteration: value = value[1:] + (element,) yield value a='abcdefg' result=window(a) list1=[] for k in result: list1