Computer Science
Which of the following functions will return the key, value pairs of a dictionary ?
- keys( )
- values( )
- items( )
- all of these
Python Dictionaries
2 Likes
Answer
items( )
Reason — items() method is used to return the list with all dictionary keys with values.
For example:
d = {'a':2, 'b':5}
print(d.items())
Output
dict_items([('a', 2), ('b', 5)])
Answered By
1 Like
Related Questions
Dictionaries are also called ……………
- mappings
- hashes
- associative arrays
- all of these
Dictionaries are …………. data types of Python.
- mutable
- immutable
- simple
- all of these
Which of the following will add a key to the dictionary only if it does not already exist in the dictionary ?
- fromkeys( )
- update( )
- setdefault( )
- all of these
Which of the following will create a dictionary with given keys and a common value ?
- fromkeys( )
- update( )
- setdefault( )
- all of these