元组比较中的python列表

卡恩

我有一个列表和一个元组(来自 sqlite 查询)以及如何检查列表中的项目是否不在 db 元组中。如果没有添加到 newJobs 列表

links = ["example.com", "mysite.com"]
newJobs = []

dbgetLink = cursor.execute("SELECT link from jobs")

Output of dbgetLink: 
('company.com',)
('mysite.com',)

this works but it checks if db is in links list.
But I want it the reverse way if the links list items are in db.

for i in links:
    for row in dbgetLink:
        if row[0] not in links:
            print("False, not in list.", row[0])
            newJobs.append(row[0])
程序员365

您可以尝试列表理解:

newJobs = [x for x in myList if not x in list(myTuple)]

myList是你的列表,myTuple是你的元组

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章