jeudi 22 juillet 2021

Python Compare Two lists with a loop and if a match is found run a few codes, and return back to the loop to test if there is another match

I am building a program in python. I have two lists and I want to loop through each of them to see if the elements are equal if they are I want to remove the one element from the list and I want to run a few codes. When this is done I want to return back to the loop to compare the lists again. until one list is empty and the program will continue.

I tried this but just can not get my mind to unblock it! Thank you.

x = [1,2,3,4,5,6,7] y = [28,1,2,3,4,5,6]

for i in x: for a in y: while i == a: x.remove(i)

How do I tell python to return to the first loop??

Aucun commentaire:

Enregistrer un commentaire