>>> combinations_with_replacement('abc', 2) # a b c [('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x ('b', 'b'), ('b', 'c'), # b . x x ('c', 'c')] # c . . x