Documentation Index
Fetch the complete documentation index at: https://mintlify.com/python/cpython/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Sets are unordered collections of unique hashable objects.
Creating Sets
PyObject* PySet_New(PyObject *iterable)
PyObject* PyFrozenSet_New(PyObject *iterable)
Example:
PyObject *set = PySet_New(NULL); // Empty set
return set;
Set Operations
int PySet_Add(PyObject *set, PyObject *key)
int PySet_Discard(PyObject *set, PyObject *key)
int PySet_Contains(PyObject *anyset, PyObject *key)
Py_ssize_t PySet_Size(PyObject *anyset)
Example:
PyObject *item = PyLong_FromLong(42);
PySet_Add(set, item);
Py_DECREF(item);
if (PySet_Contains(set, item)) {
printf("Set contains 42\n");
}
Set Methods
PyObject* PySet_Pop(PyObject *set)
void PySet_Clear(PyObject *set)
See Also