def is_sorted (l, ascending = True):
    """
    Check whether array is sorted.

    source: https://stackoverflow.com/questions/3755136/pythonic-way-to-check-if-a-list-is-sorted-or-not

    :param l: list
    :return: is sorted
    """
    if ascending:
        return all (l[i] <= l[i+1] for i in range (len (l)-1))
    else:
        return all (l[i] >= l[i+1] for i in range (len (l)-1))