

- 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
Python - Remove non-increasing elements
When it is required to remove non-increasing elements, a simple iteration is used along with comparison of elements.
Example
Below is a demonstration of the same
my_list = [5,23, 45, 11, 45, 67, 89, 99, 10, 26, 7, 11] print("The list is :") print(my_list) my_result = [my_list[0]] for elem in my_list: if elem >= my_result[-1]: my_result.append(elem) print("The result is :") print(my_result)
Output
The list is : [5, 23, 45, 11, 45, 67, 89, 99, 10, 26, 7, 11] The result is : [5, 5, 23, 45, 45, 67, 89, 99]
Explanation
A list is defined and is displayed on the console.
The first element of the list is assigned to another list.
The elements in the list are iterated over.
Every element is compared with the last element and checked to see if they are greater than or equal to the first element of the list.
If it is, then it is appended to the list.
This is the output that is displayed on the console.
- Related Questions & Answers
- Python – Remove strings with any non-required character
- Python program to find Non-K distant elements
- Count the number of non-increasing subarrays in C++
- Python – Remove Columns of Duplicate Elements
- Program to sort array by increasing frequency of elements in Python
- Upper bound and Lower bound for non increasing vector in C++
- JavaScript Remove non-duplicate characters from string
- Program to find number of operations needed to convert list into non-increasing list in Python
- Python Program to extracts elements from a list with digits in increasing order
- Longest Increasing Subsequence in Python
- Increasing Triplet Subsequence in Python
- Python program to remove Duplicates elements from a List?
- Python – Remove Elements in K distance with N
- Python program to remove elements at Indices in List
- Python Program to Remove Palindromic Elements from a List
Advertisements