Dictionary objects — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Python Module Index

3.16.0a0 Documentation

Python/C API reference manual

Concrete Objects Layer

types.MappingProxyType

Return a types.MappingProxyType object for a mapping which enforces read-only behavior. This is normally used to create a view to prevent modification of the dictionary for non-dynamic class types.

Safe for concurrent use on the same object

Determine if dictionary p contains key. If an item in p matches key, return 1, otherwise return 0. On error, return -1. This is equivalent to the Python expression key in p.

PyObject_GetItem()

Return a new strong reference to the object from dictionary p which has a key key:

borrowed reference

Return a borrowed reference to the object from dictionary p which has a key key. Return NULL if the key key is missing without setting an exception.

PyUnicode_FromString()

Exceptions that occur while this calls __hash__() and __eq__() methods or while creating the temporary str object are silently ignored. Prefer using the PyDict_GetItemWithError() function with your own PyUnicode_FromStri

Py_BEGIN_CRITICAL_SECTION

The dictionary p should not be mutated during iteration. It is safe to modify the values of the keys as you iterate over the dictionary, but only so long as the set of keys does not change. For example:

PyErr_WriteUnraisable()

If event is PyDict_EVENT_CLEARED or PyDict_EVENT_DEALLOCATED, both key and new_value will be NULL. If event is PyDict_EVENT_ADDED or PyDict_EVENT_MODIFIED, new_value will be the new value for key. If event is PyDict_EVEN

collections.OrderedDict

Python’s C API provides interface for collections.OrderedDict from C. Since Python 3.7, dictionaries are ordered by default, so there is usually little need for these functions; prefer PyDict* where possible.