#!/usr/local/bin/python import mytimer #import mymodules.mytimer2 as mytimer mytimer.start_timer() lines = 0 for row in open("words"): lines += 1 mytimer.end_timer() print "Number of lines:",lines # Added for Exercise 11, should crash mytimer.end_timer() # Now handle the exception print "We are all done"
best_count = 0 for (stem, count) in stems.items(): if stem_size == len(stem) and count > best_count: best_stem = stem best_count = count if best_stem: print "Most popular stem of size",stem_size,"is:", \ best_stem,"(occurs",best_count,"times)" ############################################################# if __name__ == '__main__': mytimer.start_timer() stems = {} for row in open("words"): for count in range(1, len(row)): stem = row[0:count] if stem in stems: stems[stem] += 1 else: stems[stem] = 1 #print "stem:",stem,"value:<",stems[stem],">" mytimer.end_timer('Load') # Process the stems