def sort_by_value(D,reverse=False):
    """
    There are many ways to sort a dictionary by value and return lists/tuples/etc.
    This is recommended for python 3 on StackOverflow.
    """
    return [(k,D[k]) for k in sorted(D,key=D.get,reverse=reverse)]