Snippets tagged “items”
7 snippets use this tag.
- Converting Dictionary to List?Python
In Python, you can convert a dictionary to a list of its keys or values using the keys() and values() methods, respectively.
- Get key by value in dictionaryPython
You can use the in keyword to check if a value exists in a dictionary, and then use the items() method to return a list of key-value pairs.
- Getting key with maximum value in dictionary?Python
You can use the built-in max() function in Python to get the key with the maximum value in a dictionary.
- How do I sort a dictionary by key?Python
In Python, dictionaries are unordered collections of key-value pairs.
- How to print a dictionary's key?Python
To print the keys of a dictionary in Python, you can use the built-in keys() method.
- Iterating over dictionaries using 'for' loopsPython
To iterate over a dictionary using a for loop, you can use the .items() method to get a list of the dictionary's keys and values, and then iterate over that list.
- What is the difference between dict.items() and dict.iteritems() in Python2?Python
In Python 2, dict.items() returns a list of the dictionary's key-value pairs, whereas dict.iteritems() returns an iterator over the dictionary's key-value pairs.