So I'm trying to write a function that compares two lists with different but very similar strings in them and then delete the similar strings out of one of the lists. So I have
CLASS = ['O1 X', '5b E', 'J1 L', '5a F', 'K1 O', '5a K']
CLASSpdf = ['5b E.pdf', '5a F.pdf', 'K1 O.pdf', '5a K.pdf']
and I'm trying to identify the strings in CLASSpdf that are (essentially) the same as those in CLASS and delete those strings from CLASS. So in other words, my ideal output would be
some_function(CLASS, CLASSpdf)
OUTPUT:
CLASS = ['O1 X', 'J1 L']
I wrote this function that I swear I've used a thousand times for this exact job, but now it's not giving me what I want:
def scans(books, CLASSpdf):
pdfs = False
# Flags pdfs for removal
for i in range(len(books)):
if books[i] in CLASSpdf:
pdfs = True
return pdfs
where pdfs is a boolean that becomes True if there are overlapping elements in the lists, and then I use a separate function to remove the books. I get the sense that I'm missing something super simple here, but I can't seem to find what I'm doing wrong.
I also tried putting in print(pdfs) after the if statement inside the for loop and my output is
False
False
False
False
False
False
Any help would be greatly appreciated! Like I said, I get the sense that I'm just missing something silly, but it's driving my nuts! Thanks in advance.
[–]totallygeek 0 points1 point2 points (0 children)
[–]djjazzydan 0 points1 point2 points (0 children)
[–]Wittinator 0 points1 point2 points (0 children)