Name

.iteritems()

Examples

element_names = {'H': 'hydrogen', 'He': 'helium', 'Li': 'lithium'}

# Iterate over each item of the dictionary:
for k, val in element_names.iteritems():
	print("The name of element " + k + " is " + val)

Description Returns tuples of the key/value pairs present in the specified dictionary, in the form of an iterator. This iterator is primarily useful as a means of iterating over every key/value pair in a dictionary in a for loop, as shown in the example above.

The iteritems() method is more memory-efficient than the items() method, as it returns each item in succession, instead of reproducing the entire dictionary as a list in memory.

Note that because of the nature of the dictionary data structure, key/value pairs returned from iteritems() will be in arbitrary order (not necessarily the order they appeared in when the dictionary was defined).
Syntax
	dict.iteritems()
Parameters
dictThe dictionary to be iterated over.
Related Dictionary
.items()

Updated on Tue Feb 27 14:07:12 2024.

If you see any errors or have comments, please let us know.