Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
one liner basic solution solution in Clear category for Ascending List by pacurar.sebastian90
from typing import Iterable
def is_ascending(items: Iterable[int]) -> bool:
'''
Removing all duplicates from the list using set(), sort them in place, and compare against the original list.
If the contents are exactly the same, or the length of the list is 1 or 0, then return True, else return False
'''
return True if list(sorted(set(items))) == items or len(items) <= 1 else False
if __name__ == '__main__':
print("Example:")
print(is_ascending([-5, 10, 99, 123456]))
# These "asserts" are used for self-checking and not for an auto-testing
assert is_ascending([-5, 10, 99, 123456]) == True
assert is_ascending([99]) == True
assert is_ascending([4, 5, 6, 7, 3, 7, 9]) == False
assert is_ascending([]) == True
assert is_ascending([1, 1, 1, 1]) == False
print("Coding complete? Click 'Check' to earn cool rewards!")
Feb. 28, 2021