#NEWLINE# def comb_w_rep( n , k ) : #NEWLINE# #INDENT# 'Combinations with repetition\n\n    Returns the list of k combinations with repetition from n objects.\n    ' #NEWLINE# if ( k == 0 ) : #NEWLINE# #INDENT# return [ [ ] ] #NEWLINE# #UNINDENT# combs = [ [ i ] for i in range ( n ) ] #NEWLINE# for i in range ( ( k - 1 ) ) : #NEWLINE# #INDENT# curr = [ ] #NEWLINE# for p in combs : #NEWLINE# #INDENT# for m in range ( p [ ( - 1 ) ] , n ) : #NEWLINE# #INDENT# curr . append ( ( p + [ m ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# combs = curr #NEWLINE# #UNINDENT# return combs