Beispiel #1
0
def presque_anagrammes(mot, n):
    """
    Renvoie la liste des "n-presque-anagrammes" de mot
    """
    clef = p11.prehash(mot)
    listeClef = p11.hashTable.getKeysWithLen(len(mot) + n)
    listeClef = filter(partial(peut_etre_presque_anagrammes, clef2=clef, n=n), listeClef)
    resultat = []
    for key in listeClef:
        resultat.extend(filter(partial(est_presque_anagramme, mot2=mot, n=n), p11.hashTable.get(key)))
    return resultat
Beispiel #2
0
def quick(mot):
    """
    Fonction renvoyant les 1-presque-anagrammes de mot. Utilisee pour repondre
    a la question du sujet.
    """
    clef = p11.prehash(mot) & 67108863
    res = []
    cpt = 1
    for i in range(0, 26):
        temp = clef | 1 << i
        if temp != clef:
            temp |= (len(mot) + 1) << 26
            L = p11.hashTable.get(temp)
            for mot2 in L:
                if est_presque_anagramme(mot2, mot, 1):
                    res.append(mot2)
    clef |= (len(mot) + 1) << 26
    for mot2 in p11.hashTable.get(clef):
        if est_presque_anagramme(mot2, mot, 1):
            res.append(mot2)
    return res