When it is required to test whether the length of rows are in increasing order, a simple iteration and a Boolean value is used.
Below is a demonstration of the same −
my_list = [, [12, 17], [25, 32, 24], [58, 36, 57, 19, 14]] print("The list is :") print(my_list) my_result = True for index in range(len(my_list) - 1) : if len(my_list[index + 1]) <= len(my_list[index]): my_result = False break print("The result is :") if(my_result == True): print("The rows are increasing in length") else: print("The rows aren't increasing in length")
The list is : [, [12, 17], [25, 32, 24], [58, 36, 57, 19, 14]] The result is : The rows are increasing in length
A list of list with integers is defined and is displayed on the console.
A variable is assigned Boolean value ‘True’.
The list is iterated over, and the size of the lists is compared with its consecutive lists.
If a specific condition is fulfilled, i.e if the length of list is lesser then the length of the consecutive list, the Boolean value is initialized to ‘True.
The control breaks out of the loop.
In the end, depending on the Boolean value, the relevant message is displayed on the console.