Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
linear
and
binary
do similar tasks: count the number of
times every word in the parameter words
occurs
and return a list of pairs. They each
function
return a list of lists, each inner list is like ["apple",
57]
indicating the word "apple" occurs 57 times in the
list of strings passed as a parameter. So these functions might return
the list below for a data source that contains the three words
occuring as many times as shown.
[ ["ant", 15], ["bat", 3], ["dog", 8] ]
tradeoff
?
f = urllib.open(datasource)
f = open(datasource)
f.close()
urllib
time
std_time
found
initialized to False in the outerloop of linear
?
w
has been found in
data
in the inner loop
w
is the first element of data
w
occurs in more then one pair of data
linear
the first time
a word is found
elt[1] += 1
data.append([w,1])
found = True
About how long to do melville8.txt based on these numbers?
binary
what is the purpose of the
first
if
statement? (more than one may be correct)
data
that's never been seen
when it's the last word
alphabetically.
elif
check and still work.
else
statement? (more
than one may be correct)
w
has been seen before.
w
is the last word in
data
w
is the first word in data