Skip to main content
 首页 » 编程设计

用于列表比较的 Python IN 运算符

2025年05月04日9softidea

我正在使用 Python 插件。
我有一个名为 station_list 的列表,我在其中附加了所有值。它包含所有整数值。
现在,我想用列表内容检查我的查询结果。我的代码是:

self.db._exec_sql(c, "select distinct (station) from station  ") 
for row in c.fetchall(): 
    for m in range(len_station_list): 
        print row[0],station_list[m] 
 
        if row[0] == station_list[m]: 
                print 'true' 

我正在用列表值检查每个选定的行。当我打印并检查时,它给出了正确的答案。但是比较出错了。
它不满足条件 if row[0] == station_list[m]:。
可能是什么问题?

请您参考如下方法:

试试这个。

x = self.db._exec_sql(c, "select distinct (station) from station  ").fetchall() 
 
y = [p for p in x if p[0] in station_list]