-
-
Save pagenoare/107697 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
print sum([1 for number in open('tel.txt').readlines() if number[0:3] == '511']) | |
# 100 loops, best of 3: 1.65 ms per loop |
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 __future__ import with_statement # if py2.5 | |
with open('tel.txt') as f: | |
print sum([1 for number in f if number[0:3] == '511']) | |
# 100 loops, best of 3: 2.07 ms per loop |
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
f = open('tel.txt') | |
c = f.readlines() | |
f.close() | |
print sum([1 for number in c if number[0:3] == '511']) | |
# 100 loops, best of 3: 1.68 ms per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment