user7711283
user7711283

Reputation:

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

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.

Upvotes: -3

Views: 154

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799510

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

Upvotes: 1

Related Questions