Created
December 4, 2012 14:48
-
-
Save andreyp/4204706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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