Here is a one liner:
all(l[i] <= l[i+1] for i in range(len(l) - 1))
If using Python 2, use xrange
instead of range
.
For reverse=True
, use >=
instead of <=
.
More Related Contents:
- How to sort a list/tuple of lists/tuples by the element at a given index?
- How to sort a list of objects based on an attribute of the objects?
- Permutations between two lists of unequal length
- How to efficiently compare two unordered lists (not sets) in Python?
- How to sort two lists (which reference each other) in the exact same way
- About Python’s built in sort() method
- Combining two sorted lists in Python
- Why does ‘.sort()’ cause the list to be ‘None’ in Python? [duplicate]
- How to sort a list of tuples according to another list
- How to efficiently compare two unordered lists (not sets)?
- Why is Bubble Sort implementation looping forever?
- Custom Python list sorting
- In Python, what is the fastest algorithm for removing duplicates from a list so that all elements are unique *while preserving order*? [duplicate]
- heapq with custom compare predicate
- Checking if all elements in a list are unique
- Accessing the list while being sorted
- Does python have a sorted list?
- Find elements of array one nearest to elements of array two
- Complexity of list.index(x) in Python
- What is the complexity of the sorted() function?
- Python: find closest string (from a list) to another string
- Given parallel lists, how can I sort one while permuting (rearranging) the other in the same way?
- Sort a list with a custom order in Python
- Python Sort One List According to Another List
- Python: How to sort a list of dictionaries by several values?
- Retrieve the two highest item from a list containing 100,000 integers
- Split a list of tuples into sub-lists of the same tuple field [duplicate]
- Nested lambda statements when sorting lists
- How to find the max number(s) in a list with tied numbers
- How to sort a list of dictionaries by a value of the dictionary in Python?