Q. Write a program to perform sorting on the given list of strings, on the basis of length of strings. That is the smallest – length string should be the first string in the list and the largest – length string should be the last string in the sorted list.
You can understand by Watching video :-
Answer :-
a = eval(input("Enter a list of string = ")) for i in range (len(a)): for j in range(len(a)-1): if len(a [ j ] ) > len(a [ j + 1 ]) : a [ j ] , a [ j + 1 ] = a [ j + 1 ] , a [ j ] print(a)
Output :-
Enter a list of string = ["Path","Express","Portal","Walla"]
['Path', 'Walla', 'Portal', 'Express']
>>>
Enter a list of string = ["Python","C++","Java","CSS"]
['C++', 'CSS', 'Java', 'Python']
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )