Q. Write a program to perform sorting on a given list of strings, on the basis of just the first letter of the strings. Ignore all other letters for sorting purposes.


Answer =


lst = eval(input("Enter a String list = "))
length = len(lst)
for i in range(1,length):
    temp = lst[i]
    j = i-1
    while j>=0 and temp < lst[ j ]:
        lst[ j+1] = lst[j]
        j = j -1
    else :
        lst[j+1] = temp
print(lst)


Output :-

Enter a String list = ["Pathwalla","Computer portal","portal","express","python","games"]
['Computer portal', 'Pathwalla', 'express', 'games', 'portal', 'python']
>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post