summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/dict.rst
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-03-08 03:16:29 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-03-08 03:16:29 (GMT)
commit00e9886bd90490e1afc729a1abac384ba70fa6a1 (patch)
tree40c539d4a7866de9d9838a64c68e4a89c13d5a91 /Doc/c-api/dict.rst
parent763edc1c6a5a212f876c5b6b018a1d2d2054a334 (diff)
downloadcpython-00e9886bd90490e1afc729a1abac384ba70fa6a1.zip
cpython-00e9886bd90490e1afc729a1abac384ba70fa6a1.tar.gz
cpython-00e9886bd90490e1afc729a1abac384ba70fa6a1.tar.bz2
Add PyDict_SetDefault. (closes #17327)
Patch by Stefan Behnel and I.
Diffstat (limited to 'Doc/c-api/dict.rst')
-rw-r--r--Doc/c-api/dict.rst9
1 files changed, 9 insertions, 0 deletions
diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst
index 6bacc32..dc8ef53 100644
--- a/Doc/c-api/dict.rst
+++ b/Doc/c-api/dict.rst
@@ -110,6 +110,15 @@ Dictionary Objects
:c:type:`char\*`, rather than a :c:type:`PyObject\*`.
+.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *default)
+
+ This is the same the Python-level :meth:`dict.setdefault`. If present, it
+ returns the value corresponding to *key* from the dictionary *p*. If the key
+ is not in the dict, it is inserted with value *defaultobj* and *defaultobj*
+ is inserted. This function evaluates the hash function of *key* only once,
+ instead of evaluating it independently for the lookup and the insertion.
+
+
.. c:function:: PyObject* PyDict_Items(PyObject *p)
Return a :c:type:`PyListObject` containing all the items from the dictionary.