if condition:
continue
else:
something()
の意味と,「最もよく起こりうることを先に判定せよ」というのは違うのではないか。
確かに以下のような場合には i < 0.8
を先に判定するほうが良いが,それとこれとは違う。
#---
import numpy as np
from time import time
n = 100000000
x = np.random.rand(n)
s = time()
s1, s2, s3 = 0, 0, 0
for i in x:
if i < 0.8:
s1 += 1
elif i < 0.9:
s2 += 1
else:
s3 += 1
print(s1, s2, s3, time() - s)
79997428 9999472 10003100 10.772604942321777
s = time()
s1, s2, s3 = 0, 0, 0
for i in x:
if i > 0.9:
s3 += 1
elif i > 0.8:
s2 += 1
else:
s1 += 1
print(s1, s2, s3, time() - s)
79997428 9999472 10003100 11.210047960281372