Identify runs in list
Chris Rebert
clp2 at rebertia.com
Sat Oct 3 23:07:44 EDT 2009
On Sat, Oct 3, 2009 at 7:53 PM, skorpio11 at gmail.com <skorpio11 at gmail.com> wrote:
> On Oct 3, 10:36 pm, Chris Rebert <c... at rebertia.com> wrote:
<snip>
>> 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. :)
Cheers,
Chris
More information about the Python-list
mailing list