finding cartesian product of a set n times (itertools.product function)
Hello, I was trying to find all the permutations of a set of length n, where all elements can be repeated any number of times, so basically a Cartesian product of set n times, where n is the length of the permutation. Now I know python itertools.product can do the same easily but I wanted to do it on my own and I wrote this code ``` def gen_perm(chars,lenn): if lenn == 1: for i in chars: yield i else: perms = gen_perm(chars,lenn-1) for i in perms: for j in chars: yield i+j ``` Now I cant think of anything better than this and I feel this is not very efficient as I have to calculate all the permutations of the previous iteration i.e. n-1 length, is there any way to make it more efficient and how do python itertools does it?