Thread: Python brevity
View Single Post
Old May 22nd, 2006, 4:25 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
I'd design it with a slightly more general purpose "gather" function, myself:
def gather(sets, groups):
    for found in sets.group(*groups):
        if found is not None: yield

found = re.finditer (pattern, doc, re.I)

medList = [x for x in gather(sets, (1, 2, 3)) for sets in found]
Although, on the other hand, if gather will only be used once, it seems a little redundant to wrap it in a separate function.
Arevos is offline   Reply With Quote