{"id":17568,"date":"2021-08-26T10:42:24","date_gmt":"2021-08-26T05:12:24","guid":{"rendered":"https:\/\/python-programs.com\/?p=17568"},"modified":"2021-11-22T18:37:12","modified_gmt":"2021-11-22T13:07:12","slug":"python-program-to-sort-words-in-alphabetic-order","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-sort-words-in-alphabetic-order\/","title":{"rendered":"Python Program to Sort words in Alphabetic Order"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find Longest Word from Sentence<\/a>
\nGiven a string and the task is to sort all words in a given sentence in alphabetic order.<\/p>\n

sort() method :<\/strong><\/p>\n

By default, the sort() method sorts the list in ascending order.<\/p>\n

split() method:<\/strong><\/p>\n

The split() method in Python divides a string into a list of strings by breaking the string with the specified separator.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = \"Hello this is btechgeeks\"<\/pre>\n

Output:<\/strong><\/p>\n

The all sorted words of given sentence in Alphabetic order :\r\nHello\r\nbtechgeeks\r\nis\r\nthis<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = \"Good morning this is btechgeeks\"<\/pre>\n

Output:<\/strong><\/p>\n

The all sorted words of given sentence in Alphabetic order :\r\nGood\r\nbtechgeeks\r\nis\r\nmorning\r\nthis<\/pre>\n

Program to Sort words in Alphabetic Order<\/h2>\n

Below are the ways to sort all words in a given sentence in alphabetic order.<\/p>\n