Professional Documents
Culture Documents
Q4. Which of the following functions will return the key, value pairs of a dictionary?
(a) keys()
(b) values()
(c) items()
(d) all of these
Q5. Which of the following can be used to delete item(s) from a dictionary?
(a) del statement
(b) get()
(c) getitem()
(d) all of these
Q6. Which of the following will raise an error if the given key is not found in the dictionary?
(a) del statement
(b) pop()
(c) getitem()
(d) all of these
Q7. Which of the following is correct with respect to above Python code?
d = {"a":3,"b":7}
(a) a dictionary d is created.
(b) a and b are the keys of dictionary d.
(c) 3 and 7 are the values of dictionary d.
(d) All of these.
Q14. Which of the following will delete key_value pair for key = "tiger" in dictionary?
di = {"loin" : "wild", "tiger" : "wild", "cat": "domestic" : "dog" : "domestic"}
(a) del di["tiger"]
(b) di[“tiger”].delete()
(c) delete(di.["tiger"])
(d) del(di.["tiger])
Q17. Which of the following will add a key to the dictionary only if it does not already exist in the
dictionary?
(a) fromkeys()
(b) update()
(c) setdefault()
(d) all of these
Q18. Which of the following will create a dictionary with given keys and a common value?
(a) fromkeys()
(b) update()
(c) setdefault()
(d) all of these
Q19. Which value is assigned to keys, if no value is specified with the fromkeys() method ?
(a) 0
(b) 1
(c) None
(d) any of these
Q20. Which of the following will raise an error if the given dictionary is empty?
(a) del statement
(b) pop()
(c) popitem()
(d) all of these
Q21. A copy of the dictionary where only the copy of the keys is created for the new dictionary, is
called _____ copy.
(a) key copy
(b) shallow copy
(c) deep copy
(d) partial copy
Q22. A copy of the dictionary where the copy of the keys as well as the values is created for the
new dictionary, is called _____ copy.
(a) key copy
(b) shallow copy
(c) deep copy
(d) partial copy
Q23. Which of the following Python codes will give the same output if
dict = {"diary":1, "book":3, "novel":5}
(i) dict.pop("book")
(ii) del dict["book"]
(iii) dict.update({"diary":1,"novel":5})
(a) (i), (ii), (iii)
(b) (i), (ii)
(c) (i), (iii)
(d) (ii), (iii)
Q25. Running the code sorted(my_dictionary, reverse = True) on a dictionary named my_dictionary
will return results sorted in what order ?
(a) Ascending order (A-Z), by key
(b) Ascending order (A-Z), by value
(c) Descending order (Z-A), by key
(d) Descending order (Z-A), by value
Q28. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which
command do we use?
a) d.size()
b) len
c) size
d) d.len()