为什么在 Cython 中将列表转换为集合不起作用?

Why converting list into set in Cython does not work?

我想实现的是将list转换成set并返回结果:

cpdef list_to_set(list huge_list):
    cdef list ids
    cdef set final_ids=()
    for ids in huge_list:
        final_ids.update(set(ids))

    return final_ids

我这样称呼它:

from core import list_to_set
.
.
.
list_to_set.list_to_set(list(dataframe['ids'].values))

我收到以下错误:

TypeError('Expected set, got tuple',)

为什么它应该是一个元组,为什么它需要一个集合而不是一个列表,因为我一直在发送一个列表?


编辑 1:

为了简化问题,我使用了以下函数并得到了同样的错误:

list_to_set.list_to_set([[12,14], [5,6]])

() 是元组文字;类型声明和实际值的类型不匹配。您需要使用 set() 代替:

cdef set final_ids = set()