summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index de7a18e..9ae7185 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -642,7 +642,17 @@ PyDict_Clear(PyObject *op)
PyMem_DEL(table);
}
-/* CAUTION: In general, it isn't safe to use PyDict_Next in a loop that
+/*
+ * Iterate over a dict. Use like so:
+ *
+ * int i;
+ * PyObject *key, *value;
+ * i = 0; # important! i should not otherwise be changed by you
+ * while (PyDict_Next(yourdict, &i, &key, &value) {
+ * Refer to borrowed references in key and value.
+ * }
+ *
+ * CAUTION: In general, it isn't safe to use PyDict_Next in a loop that
* mutates the dict. One exception: it is safe if the loop merely changes
* the values associated with the keys (but doesn't insert new keys or
* delete keys), via PyDict_SetItem().