简体   繁体   中英

python list in tuple compare

I have a list and a tuple ( from sqlite query) and what to check if the items in list are not in the db tuple. If not add to newJobs list

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])

You can try a list comprehension:

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

myList is your list and myTuple is your tuple

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