def product( fields, i=0, result='' ):
    """Takes a list of list of fields and produces a generator
       that permutes through every possible combination of fields in order."""
    if i == len( fields ):
        yield result
    else:
        for field in fields[i]:
            for x in product( fields, i+1, result + field ):
                yield x
Takes a list of list of fields and produces a generator
       that permutes through every possible combination of fields in order.
recipes/Python/355531_Simple_patternbased_string/recipe-355531.py