#NEWLINE# def combinations_with_replacement( iterable , r ) : #NEWLINE# #INDENT# pool = tuple ( pool ) #NEWLINE# n = len ( pool ) #NEWLINE# if ( ( not n ) and r ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# indices = ( [ 0 ] * r ) #NEWLINE# ( yield tuple ( ( pool [ i ] for i in indices ) ) ) #NEWLINE# while True : #NEWLINE# #INDENT# for i in reversed ( range ( r ) ) : #NEWLINE# #INDENT# if ( indices [ i ] != ( n - 1 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# indices [ i : ] = ( [ ( indices [ i ] + 1 ) ] * ( r - i ) ) #NEWLINE# ( yield tuple ( ( pool [ i ] for i in indices ) ) )