Find us on Facebook

Thursday, December 13, 2018

Lexicographic sorting


  
Aim: Implement a program to illustrate how words can be sorted lexicographically (alphabetic order).
Algorithm:
1.      Start.
2.      Read the string .
3.      Breakdown the string into a list of words using split() function.
4.      Sort the list using sort() function.
5.      Display the sorted words.
6.      Stop.
Program:
# take input from the user
my_str = input("Enter a string: ")
# breakdown the string into a list of words
words = my_str.split()
# sort the list
words.sort()
# display the sorted words
for word in words:
   print(word)
Output:
Enter a string: Hello this Is an Example With cased letters
Example
Hello
Is
With
an
cased
letters
this

0 Comments:

Popular Posts

Text Widget

Search This Blog

Powered by Blogger.

Blogger Pages

Like Canvas?

Sponsor

Footer Widgetized Areas

About Canvas

About Canvas

Subscribe Us

About

Text Widget

Tags

Total Pageviews

print pdf

cal

Most Popular

    TUPLES
 LIST and SLICING
      ASCII VALUE
Copyright © KTU Btech Cse Python Lab Manuals | Powered by Blogger
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates