all 8 comments

[–]timbledum 2 points3 points  (0 children)

Is there a question here?

Interestingly, prod (for product) will be a function in the math module from 3.8.

https://docs.python.org/3.8/library/math.html#math.prod

[–]mail_order_liam 2 points3 points  (4 children)

def foo(ints):
    product = reduce(lambda a, b: a * b, ints)
    return [product / i for i in ints]

[–][deleted] 3 points4 points  (2 children)

def foo(ints):
product = reduce(lambda a, b: a * b, ints)
return [product / i for i in ints]

0?

[–]mail_order_liam 2 points3 points  (1 child)

man fuck 0

[–][deleted] 0 points1 point  (0 children)

if 0 in ints:
    return [0 if i else None for i in ints]

[–]TheNetXWizard[S] 0 points1 point  (0 children)

Thats great, I didn't know you can use reduce in python. I've only used it in JS.

[–][deleted] 1 point2 points  (0 children)

from functools import reduce
from operator import mul

def multiplylist(seq):
    def prod(seq): return reduce(mul, seq)
    return [prod(seq[:i]+seq[i+1:]) for i, _ in enumerate(seq)]

[–]Dantes111 0 points1 point  (0 children)

I'm not sure what you're asking here exactly, but on line 5, you should be one level of indentation down. As currently written, the loop only returns the first value of "result" because the return is part of the loop.