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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sort all even numbers in ascending order and then sort all odd numbers in descending order
- Python | All Permutations of a string in lexicographical order without using recursion
- Python | Sort words of sentence in ascending order
- Print all longest common sub-sequences in lexicographical order
- Print all distinct circular strings of length M in lexicographical order
- Print all the combinations of a string in lexicographical order
- Find the k-th string in lexicographical order consisting of n-2 X's and 2 Y's
- Generate all numbers up to N in Lexicographical Order
- Lexicographical ordering using Heap Sort
- Sort first k values in ascending order and remaining n-k values in descending order
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- Lexicographical concatenation of all substrings of a string
- Lexicographical Maximum substring of string
- Find the lexicographical next balanced bracket sequence
- K-th lexicographical string of given length
- Lexicographical smallest alternate Array
- Largest lexicographical string with at most K consecutive elements
- Print all lexicographical greater permutations of a given string
- Print words of a string in reverse order
- Check if words are sorted according to new order of alphabets
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.