Recitation01 Notes
From 6.006 Wiki
(Difference between revisions)
(→Profiling list operations) |
m (→Profiling list operations) |
||
Line 1: | Line 1: | ||
==== Profiling list operations ==== | ==== Profiling list operations ==== | ||
<pre> | <pre> | ||
- | # Recitation 06 | + | # Recitation 06- WF3 |
# Last update: September 08, 2008 | # Last update: September 08, 2008 | ||
# | # |
Latest revision as of 04:16, 11 September 2008
Profiling list operations
# Recitation 06- WF3 # Last update: September 08, 2008 # # Profile adding items to a list using "+" vs. extend() items = [[i] for i in range(50000)] def list_concat(): L = [] for item in items: L = L + item def list_extend(): L = [] for item in items: L.extend(item) import profile profile.run(list_concat()) profile.run(list_extend())
Rewriting count_frequency in document distance problem
def count_frequency_mod(word_list): """ Return a list giving pairs of form: (word,frequency) """ D = {} for new_word in word_list: if D.has_key(new_word): D[new_word] = D[new_word]+1 else: D[new_word] = 1 return D.items()