All of my code passes check50 except for the last one. I come up with 5 matches and not 4 (ba, ar, rb, ba, az).
:) helpers.py exists
:) helpers.py compiles
:) detects no lines in common
:) detects one line in common
:) detects multiple lines in common
:) handles duplicate lines in common
:) handles no sentences in common
:) handles one sentence in common
:) handles multiple sentences in common
:) handles sentences with different punctuation
:) handles sentences with punctuation mid-sentence
:) handles duplicate sentences in common
:) handles no substrings in common
:) handles one substring in common
:) handles multiple substrings in common
:) handles substrings when strings are identical
:) handles substring length longer than string length
:( handles duplicate substrings in common Expected 4 matches, not 5
Here is my code:
from nltk.tokenize import sent_tokenize
def lines(a, b): """Return lines in both a and b"""
keep_a = a.splitlines()
keep_b = b.splitlines()
final = []
for z in keep_a:
for y in keep_b:
if z == y:
final.append(z)
keep_b.remove(y)
break
return final
def sentences(a, b): """Return sentences in both a and b"""
keep_a = sent_tokenize(a)
keep_b = sent_tokenize(b)
final = []
for z in keep_a:
for y in keep_b:
if z == y:
final.append(z)
keep_b.remove(y)
break
return final
def substrings(a, b, n): """Return substrings of length n in both a and b"""
final = []
keep_a = cutter(a, n)
keep_b = cutter(b, n)
print(n)
for z in keep_a:
for y in keep_b:
if z == y:
final.append(y)
keep_b.remove(y)
break
return final
def cutter(d, s): """Returns to substrings function the substrings of length n"""
give = []
sub = ""
first = 0
sec = s
while sec <= len(d):
sub = d[first:sec]
give.append(sub)
first = first + 1
sec = sec + 1
return give
Thanks in advance for your help!