Created
July 3, 2016 15:21
-
-
Save JimHaughwout/24e102c13e6c972517a0658233ce4809 to your computer and use it in GitHub Desktop.
any vs. all vs. iteration with break
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 datetime import datetime | |
from random import randint | |
data = list() | |
for i in range(100000): | |
j = randint(1,20) | |
if j == 20: | |
data.append(j) | |
else: | |
data.append(datetime(2016, 6, j, 12, j+1, j*2)) | |
s = datetime.utcnow() | |
print all(isinstance(item, datetime) for item in data) | |
e = datetime.utcnow() | |
print (e-s).total_seconds()*1000 | |
s = datetime.utcnow() | |
print any(not isinstance(item, datetime) for item in data) | |
e = datetime.utcnow() | |
print (e-s).total_seconds()*1000 | |
s = datetime.utcnow() | |
for item in data: | |
if not isinstance(item, datetime): | |
print False | |
break | |
e = datetime.utcnow() | |
print (e-s).total_seconds()*1000 | |
""" | |
python isAll.py | |
False | |
0.876 | |
True | |
0.018 | |
False | |
0.036 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment