Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
d
that stores a dictionary as shown. What the user
types is shown in italics.
>> d {'duke': 50, 'columbia': 30, 'stanford': 20} >>> d.keys() ['duke', 'columbia', 'stanford'] >>> d.values() [50, 30, 20] >>> d.items() [('duke', 50), ('columbia', 30), ('stanford', 20)] >>> [x[1] for x in d.items()] [50, 30, 20]
x[1]
in the last line is replaced by
x[0]
what is printed?
[20, 30, 50]
['duke', 'duke', 'duke']
['duke', 'columbia', 'stanford']
d['duke'] = 80
, what is printed
by the expression d.values()
?
[50, 30, 20]
[80, 30, 20]
[50, 80, 30]
for name in d: d[name] += 10 print d
{'duke': 90, 'columbia': 40, 'stanford': 30}
{'duke': 90, 'columbia': 30, 'stanford': 20}
{'duke': 90, 'columbia': 40, 'stanford': 20}
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))