+ 1
Python optimisation
how can I optimize if a<0 and b<0 and c<0 : # code ??
6 Answers
+ 10
if all([a, b, c]) < 0:
# code
pass
+ 5
thanks Kuba SiekierzyĆski !
+ 2
have you an operation to reduce the
"a<0 and b<0 and c<0" ?
+ 1
what do you want to optimize or how ?
+ 1
wait a moment i will look
edited:
not that efficient but
i,*d = 0,a,b,c
if all(d)<0:
print(yes)
+ 1
Except all() always returns a boolean, so the check `all(iterable) < 0` will never be true. Besides, what's there to be "optimized"? The code's already readable and concise at least for a check of just three parameters long. Anyway, the correct approach with all() for your sample test would be `all(x < 0 for x in (a, b, c))`.