Q. Fill in the blanks of the following code so that the values and keys of dictionary d are inverted to create dictionary fd.
d = {'a':1, 'b':2, 'c':3}
print(d)
fd = { }
for key, value in d. _____() :
fd [____] = [____]
print(fd)
Answer :-
d = {'a':1, 'b':2, 'c':3} print(d) fd = { } for key, value in d.items() : fd [value] = key print(fd)
Output :-
{'a': 1, 'b': 2, 'c': 3}
{1: 'a', 2: 'b', 3: 'c'}
>>>
It's incorrect
ReplyDeleteTell me the Problem . I think it is correct.
DeleteCan you explain
ReplyDeleteAt first you have to understand the function .item() then you come to now that how
Delete"for key, value in d.items() :" expression work .
Then I have change key of d to values of fd and value of f to key of fd.
Actually at 5th line, there is an error
ReplyDeleteCorrection
fd[value]=d[key]
You are wrong, Please check it again.
DeleteThanks you so much
ReplyDeleteWelcome : )
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )