areas = [] f = open("all_subarea.txt", "r") for x in f: x = x.strip() areas.append(x) f.close() #print(areas) userinput = input("Enter an area name: ").lower() flag = False if userinput in areas: print("no mistakes") flag = True else: print("The input is incorrect") len3 = len(userinput) #print("The input length is {}".format(inputlength)) print("Did you mean: ") for a in areas: len4 = len(a) #print(len2) mat = [[0 for e in range(len4+1)] for d in range(len3+1)] #print(mat) #range omits end range for f in range(0, len3+1): mat[f][0]= f for f in range(0, len4+1): mat[0][f] = f #print(mat) for g in range(0, len3): for h in range (0, len4): if userinput[g] == a[h]: mat[g+1][h+1] = mat[g][h] else: mat[g+1][h+1] = min(mat[g][h], mat[g][h+1], mat[g+1][h])+1 #print(mat) distance = mat[len3][len4] #print(distance) if distance < 4: print (a) flag = True if(flag==False): print("No Matches")