Is there a cleaner and a shorter way to write this conditional in python? -
>>> def accept(d1, d2): if somefunc(d1,d2) > 32: h = 1 else: h = 0 return h
does python have ternary conditional operator? doesn't give solution case 1 want return value. lambda based solution preferable.
or, perhaps trickier,
return int(somefunc(d1, d2) > 32)
note int(true) == 1
, int(false) == 0
.
Comments
Post a Comment