Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key : value pair.
In Python Dictionary, items() method is used to return the list with all dictionary keys with values.
Syntax: dictionary.items()
Parameters: This method takes no parameters.
Returns: A view object that displays a list of a given dictionary’s (key, value) tuple pair.
Example #1:
# Python program to show working # of items() method in Dictionary # Dictionary with three items Dictionary1 = { 'A': 'Geeks', 'B': 4, 'C': 'Geeks' } print("Dictionary items:") # Printing all the items of the Dictionary print(Dictionary1.items()) |
Output:
Dictionary items:
dict_items([('C', 'Geeks'), ('B', 4), ('A', 'Geeks')])
Order of these items in the list may not always be same.
Example #2: To show working of items() after modification of Dictionary.
# Python program to show working # of items() method in Dictionary # Dictionary with three items Dictionary1 = { 'A': 'Geeks', 'B': 4, 'C': 'Geeks' } print("Original Dictionary items:") items = Dictionary1.items() # Printing all the items of the Dictionary print(items) # Delete an item from dictionary del[Dictionary1['C']] print('Updated Dictionary:') print(items) |
Output:
Original Dictionary items:
dict_items([('A', 'Geeks'), ('C', 'Geeks'), ('B', 4)])
Updated Dictionary:
dict_items([('A', 'Geeks'), ('B', 4)])
If the Dictionary is updated anytime, the changes are reflected in the view object automatically.
Recommended Posts:
- Python | Get first K items in dictionary
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Python - All possible items combination dictionary
- Python - Dictionary items in value range
- Python - Remove K value items from dictionary nesting
- Python - Common items Dictionary Value List
- Python - Append items at beginning of dictionary
- Python | Sort the items alphabetically from given dictionary
- Python | Delete items from dictionary while iterating
- Python - Convert dictionary items to values
- Python - Frequency of unequal items in Dictionary
- Python | Type conversion of dictionary items
- Python program to find the sum of all items in a dictionary
- Python - Assign list items to Dictionary
- Python | Get items in sorted order from given dictionary
- Python - Sorted order Dictionary items pairing
- Python | Count number of items in a dictionary value that is a list
- Python - Column Mapped Tuples to dictionary items
- Python - Extract dictionary items with List elements
- Python Dictionary | pop() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

