Item Sorted Dictionary Recipe

class sortedcollections.ItemSortedDict(*args, **kwargs)

Sorted dictionary with key-function support for item pairs.

Requires key function callable specified as the first argument. The callable must accept two arguments, key and value, and return a value used to determine the sort order. For example:

def multiply(key, value):
    return key * value
mapping = ItemSortedDict(multiply, [(3, 2), (4, 1), (2, 5)])
list(mapping) == [4, 3, 2]

Above, the key/value item pairs are ordered by key * value according to the callable given as the first argument.

__copy__()

Return shallow copy of the mapping.

__delitem__(key)

del mapping[key]

__setitem__(key, value)

mapping[key] = value

copy()

Return shallow copy of the mapping.