Compute all products for all numbers in a python list -
let's have list :
[2,3,5,7] i want output combinations of multiplication :
[6,10,14,15,21,35,30,42,105,210] is there 1 liner in python that?
assuming forgot 70 in output...
with numpy.prod , itertools.combinations:
>>> numpy import prod >>> itertools import combinations >>> lst = [2,3,5,7] >>> [prod(x) in range(2, len(lst)+1) x in combinations(lst, i)] [6, 10, 14, 15, 21, 35, 30, 42, 70, 105, 210]
Comments
Post a Comment