def sortNeighbors(neighbors, similarities, useTuples=True, verbose=True):
    """
    Sorts each list of neighbors in decreasing order according to similarities between users
    :param neighbors: List of lists indicating the neighbors of each user, as returned by buildNeighbors()
    :param similarities: Similarity matrix between users, as returned by buildUsersGraph()
    :param useTuples: Boolean parameter, indicating if the function should return a list of list of tuples.
    :param verbose: If set to True, status prints are made during the execution of the code
    :return: A list of lists of tuples, with for each user its neighbors in decreasing order of similarity, in the form
    of (neighbor index, similarity) tuples.
    Only neighbors with positive similarity are keeped. If useTuples is set to False, the output is a simple list of
    lists, containing only neighbor indices instead of tuples to save memory
    Note : can be used in the same way for the films point of view based model
    """
    sorted_neighbors = []
    nU = similarities.shape[0]
    for ui in range(nU):
        if verbose and ui % 100 == 0:
            print(ui)
        n = [(uj, similarities[ui, uj]) for uj in neighbors[ui] if similarities[ui, uj] > 0]
        n = sorted(n, key=lambda x: x[1], reverse=True)
        if not useTuples:
            n1 = []
            for i, j in n:
                n1.append(i)
            sorted_neighbors.append(n1)  # To save memory
        else:
            sorted_neighbors.append(n)
    return sorted_neighbors