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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -