- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Check if list is strictly increasing in Python

Given a list, we may need to check for the sequence of its elements. In this article we will find out if the elements present in the list are in a strictly increasing order. Below programs achieve that objective.

## With all and zip

In this approach we first slice each element compare its value to the next element that is sliced. If all such comparisons hold true then we conclude the list is strictly in increasing order.

## Example

listA = [11,23,42,51,67] #Given list print("Given list : ",listA) # Apply all and range if (all(i < j for i, j in zip(listA, listA[1:]))): print("Yes, List is sorted.") else: print("No, List is not sorted.") # Checking again listB = [11,23,21,51,67] print("Given list : ",listB) # Apply all and range if (all(i < j for i, j in zip(listB, listB[1:]))): print("Yes, List is sorted.") else: print("No, List is not sorted.")

## Output

Running the above code gives us the following result −

Given list : [11, 23, 42, 51, 67] Yes, List is sorted. Given list : [11, 23, 21, 51, 67] No, List is not sorted.

## with itertools.starmap

The makes an iterator that computes the function using arguments obtained from the iterable. We zip the list of elements after slicing them one by one and then taking through the less than equal to operator. Please note we have used strings instead of numbers in the below exmaples.

## Example

import operator import itertools listA = ['Mon','Tue','Sun'] #Given list print("Given list : ",listA) # Apply all and range if all(itertools.starmap(operator.le, zip(listA, listA[1:]))): print("Yes, List is sorted.") else: print("No, List is not sorted.") # Checking again listB = ['Mon','Sun','Tue'] print("Given list : ",listB) # Apply all and range if all(itertools.starmap(operator.le, zip(listB, listB[1:]))): print("Yes, List is sorted.") else: print("No, List is not sorted.")

## Output

Running the above code gives us the following result −

Given list : ['Mon', 'Tue', 'Sun'] No, List is not sorted. Given list : ['Mon', 'Sun', 'Tue'] Yes, List is sorted.

- Related Questions & Answers
- Program to check whether list is strictly increasing or strictly decreasing in Python
- A strictly increasing linked list in Python
- Find groups of strictly increasing numbers in a list in Python
- Check if it is possible to make two matrices strictly increasing by swapping corresponding values only in Python
- Strictly increasing sequence JavaScript
- Make Array Strictly Increasing in C++
- Count Strictly Increasing Subarrays in C++
- Python - Check if a list is contained in another list
- Strictly increasing or decreasing array - JavaScript
- Check if list is sorted or not in Python
- Program to find length of contiguous strictly increasing sublist in Python
- Find Maximum Sum Strictly Increasing Subarray in C++
- How to check if a list is empty in Python?
- Check if one list is subset of other in Python
- Program to check sublist sum is strictly greater than the total sum of given list Python