Skip to content

Instantly share code, notes, and snippets.

@andreyp
Created December 4, 2012 14:48
Show Gist options
  • Save andreyp/4204706 to your computer and use it in GitHub Desktop.
Save andreyp/4204706 to your computer and use it in GitHub Desktop.
from operator import mul
x = [1,2,4,0,5,0]
x_mul = reduce(mul, [ y for y in x if y])
count_nil = x.count(0)
if count_nil == 1:
print [ (0 if y != 0 else x_mul) for y in x]
elif count_nil >= 2:
print [0] * len(x)
else:
print [ x_mul / y for y in x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment