Check if a List is Sorted or not - Python Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report We are given a list of numbers and our task is to check whether the list is sorted in increasing or decreasing order. For example, if the input is [1, 2, 3, 4], the output should be True, but for [3, 1, 2], it should be False.Using all()all() function checks if every pair of consecutive elements in the list is in non-decreasing order. Python a = [1, 2, 3, 4, 5] # For checking ascending order print(all(a[i] <= a[i + 1] for i in range(len(a) - 1))) b = [5, 4, 3, 2, 1] # For checking descending order print(all(b[i] >= b[i + 1] for i in range(len(b) - 1))) OutputTrue True Explanation: For the list a = [1, 2, 3, 4, 5], we are checking for ascending order and here all() method is used verify if each element is less than or equals to its next element in the list. It only returns True if the list is sorted in ascending order. For the list b = [5, 4, 3, 2, 1], we are checking descending order all() method verify if each element is greater than or equals to its next element in the list. It returns True if the list is sorted in descending order.Note: To check for strictly increasing or decreasing sequences remove the equals sign (=) from the comparison.Using sorted()sorted() function returns a sorted version of the list. If the original list is equal to its sorted version it means the list is already sorted. Python a = [1, 2, 3, 4, 5] b = [5, 4, 3, 2, 1] # Here, sorted(), sort list in ascending order print(a == sorted(a)) print(b == sorted(b)) OutputTrue False Explanation: sorted(a) returns a new sorted list.a == sorted(a) compares the original list with its sorted version. If they match, the list is sorted.Note: We can also use list.sort() method as well. To do this, we'll create a copy of the original list, sort the copy and then compare the two lists.Using for LoopWe can iterate through the list and check if each element is less than or equal to the next one, if the loop executes completely that means the list is sorted but if we break out of the loop that means the list is not sorted. Python a = [1, 2, 3, 4] res = True for i in range(len(a) - 1): if a[i] > a[i + 1]: res = False break print(res) OutputTrue Explanation: Iterates through the list and checks if each element is greater than the next one.If any element is greater than the next, res is set to False and we break the loop.Related Articles:Check for Descending Sorted ListSort List of Lists Ascending and then DescendingDifference between sorted() and sort() Check if a list is Sorted in Python Visit Course Comment More infoAdvertise with us Next Article Python - Sort list of list by specified index M manjeet_04 Follow Improve Article Tags : Python python-list Python list-programs Practice Tags : pythonpython-list Similar Reads Check if a list is empty or not in Python In article we will explore the different ways to check if a list is empty with simple examples. The simplest way to check if a list is empty is by using Python's not operator. Using not operatorThe not operator is the simplest way to see if a list is empty. It returns True if the list is empty and F 2 min read Python - Sort list of list by specified index When working with a list of lists, we often need to sort the inner lists based on the values at a specific index. Sorting by a specified index is useful in the custom ordering of multidimensional data. In this article, we will explore different ways to sort a list of lists by a specified index in Py 3 min read Python - Sort list of list by specified index When working with a list of lists, we often need to sort the inner lists based on the values at a specific index. Sorting by a specified index is useful in the custom ordering of multidimensional data. In this article, we will explore different ways to sort a list of lists by a specified index in Py 3 min read Python | sort list of tuple based on sum Given, a list of tuple, the task is to sort the list of tuples based on the sum of elements in the tuple. Examples: Input: [(4, 5), (2, 3), (6, 7), (2, 8)] Output: [(2, 3), (4, 5), (2, 8), (6, 7)] Input: [(3, 4), (7, 8), (6, 5)] Output: [(3, 4), (6, 5), (7, 8)] # Method 1: Using bubble sort Using th 4 min read Python | sort list of tuple based on sum Given, a list of tuple, the task is to sort the list of tuples based on the sum of elements in the tuple. Examples: Input: [(4, 5), (2, 3), (6, 7), (2, 8)] Output: [(2, 3), (4, 5), (2, 8), (6, 7)] Input: [(3, 4), (7, 8), (6, 5)] Output: [(3, 4), (6, 5), (7, 8)] # Method 1: Using bubble sort Using th 4 min read Python List sort() Method The sort() method in Python is a built-in function that allows us to sort the elements of a list in ascending or descending order and it modifies the list in place which means there is no new list created. This method is useful when working with lists where we need to arranged the elements in a spec 3 min read Like