advice : how do you iterate with an acc ?

vd12005 at vd12005 at
Sat Dec 3 01:45:38 CET 2005


i'm wondering how people from here handle this, as i often encounter
something like:

acc = []    # accumulator ;)
for line in fileinput.input():
    if condition(line):
        if acc:    #1
            doSomething(acc)    #1
        acc = []
if acc:    #2
    doSomething(acc)    #2

BTW i am particularly annoyed by #1 and #2 as it is a reptition, and i
think it is quite error prone, how will you do it in a pythonic way ?


More information about the Python-list mailing list