Name | .items() |
||
---|---|---|---|
Examples |
element_names = {'H': 'hydrogen', 'He': 'helium', 'Li': 'lithium'} element_items = element_names.items() # Prints [('Li', 'lithium'), ('H', 'hydrogen'), ('He', 'helium')] print(element_items) # Iterate over each item of the dictionary: for k, val in element_names.items(): print("The name of element " + k + " is " + val) | ||
Description |
Returns the key/value pairs present in the dictionary, in the form of a
list of tuples. For large dictionaries, consider using
iteritems() instead, which returns
an iterator. Note that because of the nature of the dictionary data structure, key/value pairs returned from items() will be in arbitrary order (not necessarily the order they appeared in when the dictionary was defined). |
||
Syntax | dict.items() | ||
Parameters |
| ||
Related |
Dictionary |
Updated on Mon Sep 21 15:53:24 2020.
If you see any errors or have comments, please let us know.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License