Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
data = ["apple", "pear", "cherry", "apple", "pear", "apple", "banana"] Returns: ["apple", "pear", "banana", "cherry" ]Where banana appers before cherry in the list because it's alphabetically first (break the tie of one occurrence each).
dc
(more than
one line is possible)?
def sort(data): dc = {} for w in data: # missing line here
dc[w] = dc[w] + 1
dc[w] = dc.get(w,0) + 1
dc[w] = dc[w]+1 if w in dc else 1
dc
is a dictionary storing (word,freq)
tuples from the parameter data
which of the line(s) below
creates a list of tuples sorted alphabetically (more than one is
possible)?
alph = sorted(d.items(), key=itemgetter(0))
alph = sorted(d.items(), key=itemgetter(1))
alph = sorted(d.items())
alph
is a list of (word,freq)
tuples
sorted alphabetically by word, which line creates a list that will work
for the APT, i.e., sorted by frequency, with highest frequency first,
and ties broken by lexicographical word order (more than one is
possible)?
fr = sorted(alph, key=itemgetter(1),reverse=True)
fr = sorted(alph, key=itemgetter(1))
fr = sorted(alph, reverse=True)
process_common_last
is supposed to remove all words from
the global variable _possiblewords
that do not have
common
letters in common with the last word guessed by the
computer player. A student suggests this code:
remove
method for lists or because the
!=
operator is not defined.
process_common_last
as follows:
Which one(s) of the following will change _possiblewords
correctly (more than one is possible)?
_possiblewords = list(set(_possiblewords) - set(bw))
_possiblewords = [w for w in _possiblewords if not w in bw]
_possiblewords = list(set(_possiblewords) & set(bw))