#!/usr/bin/python3
# coding=utf-8
# La première ligne sert pour python (et ipython) 2, qui n'aiment pas
# les caractères non ASCII.

# Dans ipython :
# run seance6.py

# Recyclé
def unzip (a):
    r1 = []
    r2 = []
    for e in a:
        r1.append (e[0])
        r2.append (e[1])
    return r1, r2

def frequency_table_to_sorted_list_of_reversed_pairs (frequency_table):
    r = []
    for word in frequency_table:
        r.append ((frequency_table[word], word))
    r.sort ()
    return r

def words_to_frequency_table (words):
    d = dict ({})
    words_no = len (words)
    for word in words:
        if word in d:
            d[word] = d[word] + 1.0 / words_no
        else:
            d[word] = 1.0 / words_no
    return d

