Iterating over consecutive sublists in Python
Posted
by Anthony Labarre
on Stack Overflow
See other posts from Stack Overflow
or by Anthony Labarre
Published on 2010-03-26T12:39:07Z
Indexed on
2010/03/26
12:43 UTC
Read the original article
Hit count: 270
python
|functionality
Does Python offer a way to iterate over all "consecutive sublists" of a given list L - i.e. sublists of L where any two consecutive elements are also consecutive in L - or should I write my own?
(Example: if L = [1, 2, 3], then the set over which I want to iterate is {[1], [2], [3], [1, 2], [2,3], [1, 2, 3]}. [1, 3] is skipped since 1 and 3 are not consecutive in L.)
© Stack Overflow or respective owner