What is the equivalent of "if item in list/set' in C code of a Python extension module?

147 Views Asked by At

Writing a Python extension module which is intended to speed up execution of a function written as Python script I am stuck with the problem of how to check in C-code of a Python extension module if a C-Python object is in a C-Python set/list of C-Python objects.

In other words what I am looking after is the equivalent of Python script expression item in list/set in C code of a Python extension module.

Any hints how to accomplish this are welcome.

1

There are 1 best solutions below

0
Ignacio Vazquez-Abrams On BEST ANSWER

int PySequence_Contains(PyObject *o, PyObject *value)

Determine if o contains value. If an item in o is equal to value, return 1, otherwise return 0. On error, return -1. This is equivalent to the Python expression value in o.

source