简体   繁体   中英

Python IN operator for List comparision

I am working with Python plugins.
I have my list called station_list ,to which i had appended all the values.It contains all the integer values.
Now,I wanted to check my query result with list content. My code is:

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'

I am checking each selected row with list values. When i print and check, it gives correct answer.But comparision goes wrong.
It does not satisfy condition if row[0] == station_list[m]: .
What can be the problem?

Try this.

x = self.db._exec_sql(c, "select distinct (station) from station  ").fetchall()

y = [p for p in x if p[0] in station_list]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM