Showing posts with label Sorting a list of strings. Show all posts
Showing posts with label Sorting a list of strings. Show all posts

Sorting a list of strings

# Sorting a list of strings

Nterms = int(input("Enter number of string:"))
Lstr = []

print("Enter", Nterms, "strings:")
for idx in range(0,Nterms, 1):
str1 = input()
Lstr.append(str1)

print("Original list of strings:")
print(Lstr)

Lstr = sorted(Lstr, key=lambda Lstr:Lstr[0], reverse=False)

print("List of strings after sorting:")
print(Lstr)