Not sure why, but I'm getting a syntax error when trying to execute my code:

"def sentences(a, b):SyntaxError: invalid syntax"

    from nltk.tokenize import sent_tokenize

def lines(a, b):
    """Return lines in both a and b"""

    return list(set(a.split("\n").intersection(b.split("\n")))

def sentences(a, b):
    """Return sentences in both a and b"""

    return list(set(sent_tokenize(a).intersection(sent_tokenize(b)))

def substrings(a, b, n):
    """Return substrings of length n in both a and b"""

    return list(set([a[i:i+n] for i in range(len(a)-1)].intersection([b[i:i+n] for i in range(len(a)-1)])))

In python, when you get a syntax error on an apparently correct line, look to the previous line. How many parenthesis characters in the prior return line? It's odd.

  • Ah, duh! thanks, can't believe I missed that – Joe Joe Joe Aug 29 '18 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .