def comb_w_rep(n, k):
 if (k == 0):
  return [[]]
 combs = [[i] for i in range(n)]
 for i in range((k - 1)):
  curr = []
  for p in combs:
   for m in range(p[(-1)], n):
    curr.append((p + [m]))
  combs = curr
 return combs

def comb_w_rep ( n , k ) : if ( k == 0 ) : return [ [ ] ] combs = [ [ i ] for i in range ( n ) ] for i in range ( ( k - 1 ) ) : curr = [ ] for p in combs : for m in range ( p [ ( - 1 ) ] , n ) : curr . append ( ( p + [ m ] ) ) combs = curr return combs
combinations with repetition returns the list of k combinations with repetition from n objects .