Python Programming - Dictionaries
Exercise : Dictionaries - General Questions
- Dictionaries - General Questions
36.
What does the
dictionary.pop(key, None)
method do?
Answer: Option
Explanation:
The
pop()
method with a default value of None
removes a key-value pair from a dictionary without raising an error if the key is not present.
37.
How do you check if a specific value exists in the values of a dictionary?
Answer: Option
Explanation:
The
in
keyword is used to check if a specific value exists in the values of a dictionary.
38.
What is the purpose of the
dictionary.pop(key, default_value)
method?
Answer: Option
Explanation:
The
pop()
method with a default value removes the specified key and returns its value, or returns the default value if the key is not present.
39.
What does the expression
len(dictionary.items())
return?
Answer: Option
Explanation:
The
items()
method returns a list of key-value pairs, and len()
returns the number of items, which is the total number of key-value pairs.
40.
How do you create a dictionary with keys from one list and values from another list?
Answer: Option
Explanation:
Using a dictionary comprehension with
zip()
can create a dictionary with keys from one list and values from another.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers