I'm almost there with Similarities but I just can't seem to get past the last few substring tests. I am passing all tests except the last four:
- :( handles multiple substrings in common, Expected 4 matches, not 0
- :( handles substrings when strings are identical, Expected 4 matches, not 2
- :( handles substring length longer than string length, Expected 0 matches, not 1
- :( handles duplicate substrings in common, Expected 4 matches, not 1
I've tested my code through the flask server and it all seems to work great through index.html. . .substrings are highlighted, all is well. Here's my substring code below:
def substrings(a, b, n): """Return substrings of length n in both a and b""" # TODO aSub = [a[i:i+n] for i in range(0, len(a), n)] # use slice with a range of the word's len to take 'n' chunks from word bSub = [b[i:i+n] for i in range(0, len(b), n)] # use slice with a range of the word's len to take 'n' chunks from word sameSub =  # make an empty list to store similar substrings in for x in aSub: # iterate through list A for y in bSub: # iterate through list B if x == y: # are the sentences the same? Then put the sentence in a new list (sameSent) sameSub.append(x) # Remove duplicate lines by pusing the list into a set simSub = list(set(sameSub)) return simSub
Just can't seem to figure out why I can't pass the tests. Any help is greatly appreciated.