Identify runs in list

Chris Rebert clp2 at
Sun Oct 4 05:07:44 CEST 2009

On Sat, Oct 3, 2009 at 7:53 PM, skorpio11 at <skorpio11 at> wrote:
> On Oct 3, 10:36 pm, Chris Rebert <c... at> wrote:
>> Since this sounds like homework, I won't give actual code, but here's
>> a gameplan:
>> 1. Split the list into sublists based on where the runs of zeros stop and start.
>> 2. Categorize the sublists and place them into lists-of-lists based on
>> whether they have nonzero entries.

>> To do the categorization, you'll
>> have to iterate over the original list and track how many previous 0s
>> you've seen consecutively.

Erm, s/categorization/splitting and move this sentence into point #1,
obviously. Mea culpa. :)


More information about the Python-list mailing list