New in version 2.5.
This section details the public API for set and frozenset objects. Any functionality not listed below is best accessed using the either the abstract object protocol (including PyObject_CallMethod(), PyObject_RichCompareBool(), PyObject_Hash(), PyObject_Repr(), PyObject_IsTrue(), PyObject_Print(), and PyObject_GetIter()) or the abstract number protocol (including PyNumber_And(), PyNumber_Subtract(), PyNumber_Or(), PyNumber_Xor(), PyNumber_InPlaceAnd(), PyNumber_InPlaceSubtract(), PyNumber_InPlaceOr(), and PyNumber_InPlaceXor()).
The following type check macros work on pointers to any Python object. Likewise, the constructor functions work with any iterable Python object.
Return true if p is a set object or an instance of a subtype.
New in version 2.6.
Return true if p is a frozenset object or an instance of a subtype.
New in version 2.6.
Return a new set containing objects returned by the iterable. The iterable may be NULL to create a new empty set. Return the new set on success or NULL on failure. Raise TypeError if iterable is not actually iterable. The constructor is also useful for copying a set (c=set(s)).
Return a new frozenset containing objects returned by the iterable. The iterable may be NULL to create a new empty frozenset. Return the new set on success or NULL on failure. Raise TypeError if iterable is not actually iterable.
Changed in version 2.6: Now guaranteed to return a brand-new frozenset. Formerly, frozensets of zero-length were a singleton. This got in the way of building-up new frozensets with PySet_Add().
The following functions and macros are available for instances of set or frozenset or instances of their subtypes.
Return the length of a set or frozenset object. Equivalent to len(anyset). Raises a PyExc_SystemError if anyset is not a set, frozenset, or an instance of a subtype.
Changed in version 2.5: This function returned an int. This might require changes in your code for properly supporting 64-bit systems.
Add key to a set instance. Does not apply to frozenset instances. Return 0 on success or -1 on failure. Raise a TypeError if the key is unhashable. Raise a MemoryError if there is no room to grow. Raise a SystemError if set is an not an instance of set or its subtype.
Changed in version 2.6: Now works with instances of frozenset or its subtypes. Like PyTuple_SetItem() in that it can be used to fill-in the values of brand new frozensets before they are exposed to other code.
The following functions are available for instances of set or its subtypes but not for instances of frozenset or its subtypes.
Return a new reference to an arbitrary object in the set, and removes the object from the set. Return NULL on failure. Raise KeyError if the set is empty. Raise a SystemError if set is an not an instance of set or its subtype.