Skip to content

Instantly share code, notes, and snippets.

@learner-long-life
Created December 20, 2013 16:22
Show Gist options
  • Save learner-long-life/8057238 to your computer and use it in GitHub Desktop.
Save learner-long-life/8057238 to your computer and use it in GitHub Desktop.
Supposed improvement in Python file-reading speed, submitted by one of my students
inputfile = open(filename)
#...
# I swear enumerate() makes this faster.
for i, line in enumerate(inputfile):
if readnext == True: # Previous line started with an '@'
# linescounted += 1 # For line count check.
for bp in line.rstrip():
if bp == 'G':
total_count += 1 # Increment total count on valid counts
g_count += 1
elif bp == 'C':
total_count += 1
c_count += 1
elif bp == 'A':
total_count += 1
a_count += 1
elif bp == 'T':
total_count += 1
t_count += 1
elif count_invalid == True:
total_count += 1 # Increment total count on invalid counts
seq_count += 1
readnext = False
elif readnext == False and line[0] == '@': # Read first character of line.
readnext = True # Count pairs in next line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment