Join Regular Classroom : Visit ClassroomTech

Python Dictionary – iteritems() method

It is a method in python that returns an iterator object of the dictionary.
Note: it is only for python 2.7 or below

Syntax:
dictionary.iteritems()

Example 1:

# Python code to understand iteritems() method in dictionary
# www.codewindow.in

s = {0:"CodeWindow", 1:"India", 2:"News"}
x = s.iteritems()
print(x)

Output:

<dictionary-itemiterator object at 0x7fd670f5c838>

Explanation:
Here it returned an iterator object of the dictionary.

Example 2:

# Python code to understand iteritems() method in dictionary
# www.codewindow.in

s = {"site":"CodeWindow", "country":"India", "type":"News", "platform":"IT"}
x = s.iteritems()
print(x)

Output:

<dictionary-itemiterator object at 0x7fecc3685838>

Explanation:
Here it returned an iterator object of the dictionary.


You Missed

Also Checkout