Seb wrote: >>>> def n_grams(a, n): > ... z = (islice(a, i, None) for i in range(n)) > ... return zip(*z) > ... > > I'm impressed at how succinctly this islice helps to build a list of > tuples with indices for all the required windows.
If you want it succinctly, there is this variation on the theme: n_grams = lambda a, n: zip(*(a[i:] for i in range(n))) -- By ZeD -- https://mail.python.org/mailman/listinfo/python-list