
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Program to sort all vowels at beginning then the consonants, are in sorted order in Python
Suppose we have a lowercase alphabet string s, we have to find a string with all the vowels of s in sorted sequence followed by all consonants of s in sorted sequence.
So, if the input is like "helloworld", then the output will be "eoodhlllrw", as vowels are "eo" And consonants are in sorted order "dhlllrw"
To solve this, we will follow these steps −
- k := blank string, t := blank string
- for each character c in s, do
- if c is a vowel, then
- k := k concatenate c
- otherwise,
- t := t concatenate c
- if c is a vowel, then
- return (k after sort and concatenate t after sorting)
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, s): vowels = 'aeiou' k = '' t = '' for c in s: if c in vowels : k = k + c else : t = t + c k = ''.join(sorted(k)) t = ''.join(sorted(t)) return k + t ob = Solution() print(ob.solve("helloworld"))
Input
"helloworld"
Output
eoodhlllrw
- Related Articles
- Program to find longest substring of all vowels in order in Python
- How to detect vowels vs consonants in Python?
- Replace All Consonants with Nearest Vowels In a String using C++ program
- Java Program to Count the Number of Vowels and Consonants in a Sentence
- Swift Program to Count the Number of Vowels and Consonants in a Sentence
- Haskell Program to Count the Number of Vowels and Consonants in a Sentence
- Kotlin Program to Count the Number of Vowels and Consonants in a Sentence
- Program to find all prime factors of a given number in sorted order in Python
- C# Program to count number of Vowels and Consonants in a string
- Python program to sort string in custom order
- C Program to count vowels, digits, spaces, consonants using the string concepts
- Alternating Vowels and Consonants in C/C++
- Frequency of vowels and consonants in JavaScript
- Validating alternating vowels and consonants in JavaScript
- Program to find minimum value to insert at beginning for all positive prefix sums in Python

Advertisements