Skip to content

Instantly share code, notes, and snippets.

@pagenoare
Forked from ravicious/numbers.rb
Created May 6, 2009 19:49
Show Gist options
  • Save pagenoare/107697 to your computer and use it in GitHub Desktop.
Save pagenoare/107697 to your computer and use it in GitHub Desktop.
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
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
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