def sansDC(ch):
    "cette fonction renvoie la chaine ch amputee de son dernier caractere"
    nouv = ""
    i, j = 0, len(ch) -1
    while i < j:
        nouv = nouv + ch[i]
        i = i + 1
    return nouv

def remplirListe(liste):
    of = open(nomF, 'r')
    while 1:
        ligne = of.readline()
        if ligne == "":
            break
        # afficher en omettant le dernier caractere (= fin de ligne) :
        liste.append(sansDC(ligne))
    of.close()

def ecrireDansFichier(liste):
    of = open("dico_ruzzle.txt", 'a')
    i=0
    nbr_mots = len(liste)
    while i<nbr_mots:
        if len(liste[i])>1 and len(liste[i])<17 and '-' not in liste[i] and "'" not in liste[i]:
            # ecrit les mots de 2 à 16 lettres, sans tiret
            of.write(liste[i])
            of.write("\n")
        i += 1
    of.close()

    
nomF="ruzzle_dictionnaire.txt"
liste=[]
remplirListe(liste)
ecrireDansFichier(liste)

