Python function: Check descending sort & empty list
Write a Python function that checks if a given list is sorted in descending order. Return None if the list is empty.
Sample Solution:
Code:
Output:
List is not sorted in descending order.
List is not sorted in descending order.
In the above exercise, the "is_descending_sorted()" function checks if the input list is empty. If it's empty, it returns 'None'. Otherwise, it checks if all pairs of adjacent elements are descending by using a generator expression and the "all()" function. If all pairs are in descending order, it returns 'True'; otherwise, it returns 'False'. The "main()" function demonstrates the function's usage by providing a sample list of number.
Flowchart:

Previous: Python program for handling empty strings.
Next: Handle empty input.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics