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'}
>>>

8 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Replies
    1. Tell me the Problem . I think it is correct.

      Delete
  2. Can you explain

    ReplyDelete
    Replies
    1. At first you have to understand the function .item() then you come to now that how
      "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.

      Delete
  3. Actually at 5th line, there is an error
    Correction
    fd[value]=d[key]

    ReplyDelete
  4. Thanks you so much

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post