def findCloseBiblios(biblioKeys, target, n=5):
    target = target.lower()
    names = []
    superStrings = []
    def addName(name, distance):
        tuple = (name, distance)
        if len(names) < n:
            names.append(tuple)
            names.sort(key=lambda x:x[1])
        elif distance >= names[-1][1]:
            pass
        else:
            for i, entry in enumerate(names):
                if distance < entry[1]:
                    names.insert(i, tuple)
                    names.pop()
                    break
        return names
    for name in biblioKeys:
        if target in name:
            superStrings.append(name)
        else:
            addName(name, levenshtein(name, target))
    return sorted(s.strip() for s in superStrings) + [n.strip() for n,d in names]
Finds biblio entries close to the target.
dataset/ETHPy150Open tabatkins/bikeshed/bikeshed/biblio.py/findCloseBiblios