Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Ben Finney
[EMAIL PROTECTED] wrote: acc = []# accumulator ;) for line in fileinput.input(): if condition(line): if acc:#1 doSomething(acc)#1 acc = [] else: acc.append(line) if acc:#2 doSomething(acc)#2 Looks like you'd be better

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Bengt Richter
On 2 Dec 2005 18:34:12 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: It looks to me like itertools.groupby could get you close to what you want, e.g., (untested) Ah, groupby. The generic string.split() equivalent. But the doc said the input needs to be sorted. seq =

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread bonono
Bengt Richter wrote: On 2 Dec 2005 18:34:12 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: It looks to me like itertools.groupby could get you close to what you want, e.g., (untested) Ah, groupby. The generic string.split() equivalent. But the doc said the input needs to be

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Scott David Daniels
Jeffrey Schwab wrote: [EMAIL PROTECTED] wrote: hello, i often encounter something like: acc = []# accumulator ;) for line in fileinput.input(): if condition(line): if acc:#1 doSomething(acc)#1 acc = [] else: acc.append(line)

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Bengt Richter
On 3 Dec 2005 03:28:19 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: On 2 Dec 2005 18:34:12 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: It looks to me like itertools.groupby could get you close to what you want, e.g., (untested) Ah, groupby. The generic

Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Bengt Richter
On 2 Dec 2005 17:08:02 -0800, [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: hello, 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

Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Dan Sommers
On 2 Dec 2005 16:45:38 -0800, [EMAIL PROTECTED] wrote: hello, 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

Re: advice : how do you iterate with an acc ?

2005-12-02 Thread bonono
Bengt Richter wrote: It looks to me like itertools.groupby could get you close to what you want, e.g., (untested) Ah, groupby. The generic string.split() equivalent. But the doc said the input needs to be sorted. -- http://mail.python.org/mailman/listinfo/python-list

Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: hello, 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 = [] else: