Quiz: Dictionary

To View Tricks: Login Required

Number of Questions: 10

Question: 6 -

Which of the following will give error?

Suppose dict1={"a":1,"b":2,"c":3}

Options:
  1. print(dict1.get("b"))

  2. dict1["a"]=5

  3. print(len(dict1))

  4. None of these.

  5. Answer:

    None of these.

    Solution not available.

Question: 7 -

Which of the following is False regarding dictionary in Python?

dict={"Joey":1,"Rachel":2}
dict.update({"Phoebe":2})
print(dict)

Options:
  1. None of the above

  2. Values of a dictionary can be string,integers or combination of both.

  3. The value of a dictionary can be accessed with the help of indices.

  4. Keys of a dictionary can be string,integers or combination of both

  5. Answer:

    The value of a dictionary can be accessed with the help of indices.

    Solution not available.

Question: 8 -

Which of the following will delete key_value pair for key="tiger" in dictionary?

dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}

Options:
  1. del dic["tiger"]

  2. del(dic.["tiger"])

  3. delete(dic.["tiger"])

  4. dic["tiger"].delete()

  5. Answer:

    del dic["tiger"]

    Solution not available.

Question: 9 -

Which of the following Python codes will give same output if
(i) dict.pop("book")
(ii) del dict["book"]
(iii) dict.update({"diary":1,"novel":5})

dict={"diary":1,"book":3,"novel":5}

Options:
  1. i, ii

  2. i, ii, iii

  3. i, iii

  4. ii, iii

  5. Answer:

    i, ii

    Solution:

    del dict["book"] and dict.pop("book") are thefollowing Python codes will give same output.


Question: 10 -

What will be the following Python code?

dict1={"a":10,"b":2,"c":3}
str1=""
for i in dict1:
    str1=str1+str(dict1[i])+" "
    str2=str1[:-1]
print(str2[::-1])

Options:
  1. Error

  2. 3, 2, 01

  3. 3, 2

  4. 3, 2, 10

  5. Answer:

    3, 2, 01

    Solution not available.