
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to extracts elements from a list with digits in increasing order
When it is required to extracts elements from a list with digits in increasing order, a simple iteration, a flag value and the ‘str’ method is used.
Below is a demonstration of the same −
Example
my_list = [4578, 7327, 113, 3467, 1858] print("The list is :") print(my_list) my_result = [] for element in my_list: my_flag = True for index in range(len(str(element)) - 1): if str(element)[index + 1] <= str(element)[index]: my_flag = False if my_flag: my_result.append(element) print("The result is :") print(my_result)
Output
The list is : [4578, 7327, 113, 3467, 1858] The result is : [4578, 3467]
Explanation
A list is defined and displayed on the console.
An empty list is defined.
The list is iterated over, and flag is set to Boolean ’True’.
Every element is first converted to list, and compared with its consecutive element.
If second element is less than or equal to first element, the flag value is set to Boolean ‘False’.
If the Boolean flag is ‘True’ in the end, the element is appended to the empty list.
This is the output that is displayed on the console.
- Related Articles
- Maximum sum of increasing order elements from n arrays in C++ program
- Program to find squared elements list in sorted order in Python
- Program to create a list with n elements from 1 to n in Python
- Python program to remove Duplicates elements from a List?
- Python Program to Remove Palindromic Elements from a List
- Python Program to Extract Elements from a List in a Set
- C# Program to display the last three elements from a list in reverse order
- Python program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple
- Program to get indices of a list after deleting elements in ascending order in Python
- Python program to find N largest elements from a list
- Maximum sum of increasing order elements from n arrays in C++
- Program to find duplicate item from a list of elements in Python
- Program to count number of elements in a list that contains odd number of digits in Python
- Python program to sort tuples in increasing order by any key.
- Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple using Python program

Advertisements