I have written a simple for loop meant to check if all of the words in one list are found in a larger list. It is a practice question found here.
I do not understand why my function does not execute properly - After running it, what is left in the sample list "note2" is ['one','today'], so it seems like the loop is somehow skipping over those words. Why is that?! I do not understand it conceptually.
Thank you for your help on this.
Example lists (two pairs of examples):
mag1=['two', 'times', 'three', 'is', 'not', 'four']
note1=['two', 'times', 'two', 'is', 'four']
mag2=['give', 'me', 'one', 'grand', 'today', 'night']
note2=['give','one','grand','today']
Function:
def checkMagazine(magazine, note):
#Counter(note1).max
for word in note:
if word in magazine:
magazine.remove(word)
note.remove(word)
#print(magazine)
#print(note)
#print(note)
if len(note)>0:
#ans="No"
print("No")
else:
#ans="Yes"
print("Yes")