def product(*args, **kwargs):
p = [[]]<EOL>for iterable in map(tuple, args) * kwargs.get("<STR_LIT>", <NUM_LIT:1>):<EOL><INDENT>p = [x + [y] for x in p for y in iterable]<EOL><DEDENT>for p in p:<EOL><INDENT>yield tuple(p)<EOL><DEDENT>
Yields all permutations with replacement:
        list(product("cat", repeat=2)) => 
        [("c", "c"), 
         ("c", "a"), 
         ("c", "t"), 
         ("a", "c"), 
         ("a", "a"), 
         ("a", "t"), 
         ("t", "c"), 
         ("t", "a"), 
         ("t", "t")]