Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
These questions are about the Clever Hangman assignment.
Suppose that the game is just starting and the entire dictionary of words that the computer can choose from in guessing a five-letter word is:
["apple", "upper", "happy", "puppy", "hippo", "creep", "pumps", "bicep", "vocal", "poppy", "space", "aphid", "opera", "alpha", "bagel", "maple", "viper", "grape", "trips", "paper", "ghost", "peeps" ]
['happy', 'puppy', 'hippo', 'poppy']
['happy', 'hippo']
['happy', 'hippo', 'apple', 'upper']
get_pattern
is designed to produce a list/pattern such as those
described above, e.g., so that the code
below stores ['_','p','_','_','_]
in variable pattern.
temp = ['_']*5 word = "opera" pattern = get_pattern(temp,word,'p')
What is the purpose of using the
code nt = list(template) above?
template and word
have the same length
template
template
so that the parameter isn't changed.
get_pattern
is a list. Which code below creates a string from the list, e.g.,
"_p___" from
['_','p','_','_','_']
''.join(pattern)
','.join(pattern)
' '.join(pattern)
"_ p p _ _" can be a key
in a dictionary, mapped to all the possible words that have
that pattern, e.g., some entries from the list above include:
{'p_p__': ['paper'],
'_____': ['vocal', 'bagel', 'ghost'],
Once the dictionary is created, which code below
below finds the key (string) with the value (list) that has
the most elements. The dictionary is d. More than
one can be correct.
sorted(d.items(),key=operator.itemgetter(1), reverse=True)[0]
sorted(d.items(),key=operator.itemgetter(1))[-1]
sorted([(d[key],key) for key in d],reverse=True)[0][1]