Python Comparing two lists of strings for similarities
fuzzywuzzy, list, python
Solution
Something like this maybe. Checks if every word in the destination folder exists in the filename
dstdir = ['The Big Bang Theory', 'Dexter', 'Spawn' ]
srcdir = ['the.big.bang.theory s1e1', 'the.big.bang.theory s1e2', 'dexter s2e01']
for source in srcdir:
for destination in dstdir:
destinationWords = destination.split()
if all(word.lower() in source.lower() for word in destinationWords):
print 'succes ', destination, ' ', source
outputs:
succes The Big Bang Theory the.big.bang.theory s1e1
succes The Big Bang Theory the.big.bang.theory s1e2
succes Dexter dexter s2e01
Problem
I'm very new at Python but I thought it would be fun to make a program to sort all my downloads, but I'm having a little trouble with it. It works perfectly if my destination only has one word in it but if the destination has two words or more this is where it goes wrong and the program gets stuck in a loop. Does anybody have a better idea to compare the lists than me ``` >>>for i in dstdir: >>> print i.split() ['CALIFORNICATION'] ['THAT', "'70S", 'SHOW'] ['THE', 'BIG', 'BANG', 'THEORY'] ['THE', 'OFFICE'] ['DEXTER'] ['SPAWN'] ['SCRUBS'] ['BETTER', 'OF', 'TED'] >>>for i in dstdir: >>> print i.split() ['Brooklyn.Nine-Nine.S01E16.REAL.HDTV.x264-EXCELLENCE.mp4'] ['Revolution', '2012', 'S02E12', 'HDTV', 'x264-LOL[ettv]']] ['Inequality', 'for', 'All', '(2013)', '[1080p]'] ``` This is an example of the lists output. I have a destination directory with only folders in it and a download directory. I want to make a program to automatically look at the source file name and then look at the destination name. if the destination name is in the source name then I have the yes to go ahead and copy the downloaded file so it is sorted in my collection. ``` destination = '/media/mediacenter/SAMSUNG/SERIES/' source = '/home/mediacenter/Downloads/' dstdir = os.listdir(destination) srcdir = os.listdir(source) for i in srcdir: source = list(i.split()) for j in dstdir: count = 0 succes = 0 destination = list(j.split()) if len(destination) == 1: while (count < len(source)): if destination[0].upper() == source[count].upper(): print 'succes ', destination, ' ', source count = count + 1 elif len(destination) == 2: while(count < len(source)): if (destination[0].upper() == source[count].upper()): succes = succes + 1 count = len(source) count = 0 while(count < len(source)): if (destination[1].upper() == source[count].upper()): succes = succes + 1 count = len(source) count = 0 if succes == 2: print 'succes ', destination, ' ', source ``` For now I'm happy with only "success" as an output; I will figure out how to copy files as it will be a totally different problem for me in the near future