簡體   English   中英

用於列表比較的Python IN運算符

[英]Python IN operator for List comparision

我正在使用Python插件。
我有我的名單稱為station_list ,而我已經追加所有values.It包含了所有的整數值。
現在,我想用列表內容檢查查詢結果。 我的代碼是:

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM