Problem with Lexical Scope

Duncan Booth duncan.booth at invalid.invalid
Mon Dec 12 14:02:35 CET 2005

jslowery at wrote:

> reducer does have no side effects so I suppose short-circuting it would
> be the best thing. I think the only thing about the last example is
> that it starts things off with a zero. I think that would boink it.

In that case, and assuming that fields contains at least one entry:

def collect(fields, reducer):
     def rule(record):
        f = iter(fields)
        prev = record[]
        for field in f: 
            if not reducer(prev, record[field]):
                return False
            prev = record[field]
        return True
     return rule

More information about the Python-list mailing list