Skip to content
Advertisement

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement