The Wayback Machine - https://web.archive.org/web/20240529222748/https://www.geeksforgeeks.org/python-dictionary-items-method/
Open In App

Python Dictionary items() method

Last Updated : 04 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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: 
 

Python3




# 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([('A', 'Geeks'), ('B', 4), ('C', 'Geeks')])

Order of these items in the list may not always be same. 
  
Example #2: To show working of items() after modification of Dictionary. 
 

Python3




# 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.
 



Previous Article
Next Article

Similar Reads

Python Program to find the profit or loss when CP of N items is equal to SP of M items
Given [Tex]N   [/Tex]and [Tex]M   [/Tex]denoting that the Cost Price of N articles is equal to the Selling Price of M articles. The task is to determine the profit or Loss percentage. Examples:  Input: N = 8, M = 9 Output: Loss = -11.11% Input: N = 8, M = 5 Output: Profit = 60% Formula:-  Below is the implementation of the above approach: C/C++ Cod
1 min read
Python program to find the sum of all items in a dictionary
Given a dictionary in Python, write a Python program to find the sum of all items in the dictionary. Examples: Input : {'a': 100, 'b':200, 'c':300}Output : 600 Input : {'x': 25, 'y':18, 'z':45}Output : 88 Method #1: Using Inbuilt sum() Function Use the sum function to find the sum of dictionary values. C/C++ Code # Python3 Program to find sum of #
6 min read
Python | Delete items from dictionary while iterating
A dictionary in Python is an ordered collection of data values. Unlike other Data Types that hold only a single value as an element, a dictionary holds the key: value pairs. Dictionary keys must be unique and must be of an immutable data type such as a: string, integer or tuple. Note: In Python 2 dictionary keys were unordered. As of Python 3, they
3 min read
Python | Count number of items in a dictionary value that is a list
In Python, dictionary is a collection which is unordered, changeable and indexed. Dictionaries are written with curly brackets, and they have keys and values. It is used to hash a particular key. A dictionary has multiple key:value pairs. There can be multiple pairs where value corresponding to a key is a list. To check that the value is a list or
5 min read
Python | Get items in sorted order from given dictionary
Given a dictionary, the task is to get all items from the dictionary in sorted order. Let's discuss different ways we can do this task. Method #1: Using sorted() C/C++ Code # Python code to demonstrate # to get sorted items from dictionary # initialising _dictionary ini_dict = {'a': 'akshat', 'b': 'bhuvan', 'c': 'chandan'} # printing iniial_diction
3 min read
Python | Get first K items in dictionary
While working with dictionaries, we can come across a problem in which we might have to get just some of the initial keys in dictionary. This problem can typically occur in cases of the web development domain. Let's discuss certain ways in which this problem can be solved. Method #1 : Using items() + list slicing To solve this problem, a combinatio
6 min read
Python | Type conversion of dictionary items
The interconversion of data types is quite common, and we may have this problem while working with dictionaries as well. We might have a key and corresponding list with numeric alphabets, and we with to transform the whole dictionary to integers rather than string numerics. Let's discuss certain ways in which this task can be performed. Method #1 :
6 min read
Python | Sort the items alphabetically from given dictionary
Given a dictionary, write a Python program to get the alphabetically sorted items from given dictionary and print it. Let’s see some ways we can do this task. Code #1: Using dict.items() C/C++ Code # Python program to sort the items alphabetically from given dictionary # initialising _dictionary dict = {'key2' : 'For', 'key3': 'IsGeeks', 'key1' : '
1 min read
Python - Frequency of unequal items in Dictionary
Sometimes, while working with Python, we can come across a problem in which we need to check for the unequal items count among two dictionaries. This has an application in cases of web development and other domains as well. Let’s discuss certain ways in which this task can be performed. Method #1: Using dictionary comprehension This particular task
5 min read
Python - Common items Dictionary Value List
The functionality of union has been discussed many times. But sometimes, we can have a more complex container, in which we need to check for the intersection of lists which are in form of keys of dictionary. Let’s discuss certain ways to solve this type of problem. Method #1: Using Loops Using loops is a naive brute force approach to perform this p
10 min read