dict = {}
list = ['a', 'b', 'c', 'd']
for i in range(len(list)-1):
dict[list[i]] = (list[i],) >>> adding list's element to the dictionary by creating a tuple containing a single list element
>>> dict = {'a': ('a',), 'b': ('b',), 'c': ('c',)}
for i in sorted(dict.keys()):
k = dict[i]
print(k[0])
>>>> a
b
c
print(k) >>> ('a',)
('b',)
('c',)
The other two options will generate errors
>>> Answer is A
From my perspective, each option doesn't match the requirements of this excercise. The correct answer is use a print(i) above the second loop for!
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
megan_mai
2 months, 4 weeks agochristostz03
3 months agobrunoestudos
3 months, 2 weeks ago