def reverse_dictionary(dictionary):
    """Build a reversed dictionary of the one given in argument
    (i.e. keys become values and values become keys).

    reverse_dictionary({key1:val1, key2:val1, key3:val2})
    returns {val1:[key1, key2], val2:[key3]}."""
    reversed_dictionary = {}
    for key, value in list(dictionary.items()):
        if value not in reversed_dictionary:
            reversed_dictionary[value] = []
        reversed_dictionary[value].append(key)
    return reversed_dictionary
