mercredi 20 janvier 2021

If-statement not behaving as expected

I am trying to do a comparison between two lists and I dont want a user to be printed if he exists in both source and destination database. I tried to use a if statment, but for some reason I dont understand, even though user "Will" exists in destination database, he is still being printed. would you please help me figuring this out? thank you

source_database = [("John","Smith","1985"),("Will","Tomson","1958")]
destination_database = [("John","Smith","1985"),("Will","Tomson","1956")]

users_to_add = [user for user in source_database if user not in destination_database]
for users in users_to_add:
    if users not in  destination_database:
        print(users)

else:
    continue

Output:

('Will', 'Tomson', '1958')

Aucun commentaire:

Enregistrer un commentaire