Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
x =
['s','e','c','r','e','t']
into the string s =
"secret"
. More than one may be correct.
s = str(x)
s = ''.join(x)
s = [''+p for p in x]
x = ['s','e','c','r','e','t']
. The list comprehension below
creates a new list, which of the choices represents the result
of the list comprehension?
sub = ['e' if x[i] == 'e' else '_' for i in range(len(x))]
sub = ['_', 'e', '_', '_', 'e', '_']
sub = ['e', 'e', 'e,' 'e', 'e', 'e']
sub = ['s', '_', 'c', 'r', '_', 't']
x = ['s','e','c','r','e','t']
. What is
the value of the list comprehension below.
sub = [ch if x[i] == 'e' else '_' for i,ch in enumerate(x)]
sub = ['_', 'e', '_', '_', 'e', '_']
sub = ['e', 'e', 'e,' 'e', 'e', 'e']
sub = ['s', '_', 'c', 'r', '_', 't']
di
shown below:
Which of the following is the value of the list comprehension shown:
pairs = sorted([(len(di[x]),x) for x in di])
pairs = [(3,'c'), (4,'a'), (4,'e'), (5,'b')]
pairs = [(5,'b'), (4,'a'), (4,'e'), (3,'c')]
pairs = [(4,'a'), (5,'b'), (3,'c'), (4,'e')]
di
in the code above. The code
below stores a list in variable best
.
What value is stored in best
?
[]
['f','g','h','i','j']
['a','b','c']
best
given the dictionary di
? (more than one is possible)
best = di[sorted([(len(di[x]),x) for x in di])[-1][1]]
best = ['f', 'g','h','i', 'j']
best = di[sorted([(x,len(di[x])) for x in di], key=itemgetter(1),
reverse=True)[0][0]]