Dictionaries are mutable unordered collections (they do not record element position or order of insertion) of key-value pairs. Keys within the dictionary must be unique and must be hashable. That includes types like numbers, strings and tuples. Lists and dicts can not be used as keys since they are mutable. Dictionaries in other languages are also called hash tables or associative arrays.
Numeric types used for keys obey the normal rules for numeric comparison: if two numbers compare equal (such as 1 and 1.0) then they can be used interchangeably to index the same dictionary entry. (Note however, that since computers store floating-point numbers as approximations it is usually unwise to use them as dictionary keys.)
Dictionary Views Operators¶
- & (intersection)
- Returns only the elements that appear both in the dictview and the specified iterable.
- ^ (symmetric difference)
- Returns the elements that appear in either the dictview or the specified iterable, but not in both.
- - (difference)
- Returns the elements that appear in the dictview and not in the specified iterable.
- | (union)
- Returns all the elements that appear in the dictview and the specified iterable.
- Returns an int type specifying number of elements in the collection.
- Returns the smallest item from a collection.
- Returns the largest item in an iterable or the largest of two or more arguments.
- Returns a total of the items contained in the iterable object.
- Returns a sorted list from the iterable.
- Returns a reverse iterator over a sequence.
- Returns a Boolean value that indicates whether the collection contains only values that evaluate to True.
- Returns a Boolean value that indicates whether the collection contains any values that evaluate to True.
- Returns an enumerate object.
- Returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.