1
def substrings(a, b, n):
    """Return substrings of length n in both a and b"""
    global seta
   global setb
    x = []
    y = []
    for i in range(len(a) - n + 1):
            x.append(a[i:i+n])
            seta = set(x)
    for i in range(len(b) - n + 1):
            y.append(b[i:i+n])
            setb = set(y)
    return seta & setb

This is my code for substrings. Error is

handles substring length longer than string length Expected 0 matches, not 1

So I tried using if and while to check whether n is smaller than a and b but they don't work! What am I supposed to do here?

1

I got it. I got confused with the local and global variable of seta = set(x) and setb = set(y)

You must log in to answer this question.

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