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.
Choose sorting algorithm of yourself.
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[0] < lst[ j ][ 0 ]:
lst[ j+1] = lst[j]
j = j -1
else :
lst[ j+1] = temp
print(lst)
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )