Given a strings, we need to sort the words in lexicographical order (dictionary order).
Input : "hello python program how are you" Output : are hello how program python you Input : "Coders loves the algorithms" Output : Coders algorithms loves the
Note: The words which have first letter is capital letter they will print according alphabetical manner.
Approach used in this program is very simple. Split the strings using split() function. After that sort the words in lexicographical order using sort(). Iterate the words through loop and print each word, which are already sorted.
alphabetical example hello how in is manner sort the this to word
- Python | Sort words of sentence in ascending order
- Python | All Permutations of a string in lexicographical order without using recursion
- Print all the combinations of a string in lexicographical order
- Lexicographical ordering using Heap Sort
- Print all longest common sub-sequences in lexicographical order
- Print all distinct circular strings of length M in lexicographical order
- Python | Sort Tuples in Increasing Order by any key
- Python | Reverse Order Sort in String List
- Python List Comprehension | Sort even-placed elements in increasing and odd-placed in decreasing order
- Sort all even numbers in ascending order and then sort all odd numbers in descending order
- Check if words are sorted according to new order of alphabets
- Print words of a string in reverse order
- Reorder the position of the words in alphabetical order
- Python | Sort list according to other list order
- Sort first k values in ascending order and remaining n-k values in descending order
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.