Python 扩展模块的 C 代码中的“if item in list/set”的等价物是什么?
What is the equivalent of "if item in list/set' in C code of a Python extension module?
正在编写一个 Python 扩展模块,它旨在加速作为 Python 脚本编写的函数的执行 我被如何检查 [= 的 C 代码的问题困扰20=] 扩展模块,如果 C-Python 对象在 C-Python set/list of C-Python 对象中。
换句话说,我正在寻找的是 Python 扩展模块的 C 代码中的 Python 脚本表达式 item in list/set
的等价物。
欢迎提供如何完成此操作的任何提示。
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
.
正在编写一个 Python 扩展模块,它旨在加速作为 Python 脚本编写的函数的执行 我被如何检查 [= 的 C 代码的问题困扰20=] 扩展模块,如果 C-Python 对象在 C-Python set/list of C-Python 对象中。
换句话说,我正在寻找的是 Python 扩展模块的 C 代码中的 Python 脚本表达式 item in list/set
的等价物。
欢迎提供如何完成此操作的任何提示。
int
PySequence_Contains(PyObject *o, PyObject *value)
Determine if o contains value. If an item in o is equal to value, return
1
, otherwise return0
. On error, return-1
. This is equivalent to the Python expressionvalue in o
.