Pythonic way to compute all combinations of products
Say I have a list of prime numbers [ 2,3,5 ] and I would like to get a
list (or an iterator) of all N^3 such products:
pow( 2, 0 ) * pow( 3, 0 ) * pow( 5, 0 )
pow( 2, 1 ) * pow( 3, 0 ) * pow( 5, 0 )
pow( 2, 0 ) * pow( 3, 1 ) * pow( 5, 0 )
pow( 2, 0 ) * pow( 3, 0 ) * pow( 5, 1 )
pow( 2, 1 ) * pow( 3, 1 ) * pow( 5, 0 )
pow( 2, 0 ) * pow( 3, 1 ) * pow( 5, 1 )
pow( 2, 1 ) * pow( 3, 0 ) * pow( 5, 1 )
[...]
pow( 2, N-1 ) * pow( 3, N-1 ) * pow( 5, N-1 )
What is the pythonic way to do that? (in the case of the list of length L)
No comments:
Post a Comment