Q:

Write a Python program to check whether a specified list is sorted or not

0

Write a Python program to check whether a specified list is sorted or not

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def is_sort_list(nums):
    result = all(nums[i] <= nums[i+1] for i in range(len(nums)-1))
    return result

nums1 = [1,2,4,6,8,10,12,14,16,17]
print ("Original list:")
print(nums1)
print("\nIs the said list is sorted!")
print(is_sort_list(nums1)) 

nums2 = [2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,4,6,9,1,2]
print ("\nOriginal list:")
print(nums1)
print("\nIs the said list is sorted!")
print(is_sort_list(nums2))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now