Given a string S, remove all consonants and print the modified string that contains vowels only.
Example 1:
Input
S = "abEkipo"
Output
aEio
Explanation : a, E, i, o are only vowels in the string.
Example 2:
Input
S = "rrty"
Output
No Vowel
Explanation: There are no vowels.
Your Task: You don't need to read input or print anything.Your task is to complete the function removeConsonants() which takes a string as input parameters, and returns the modified string that contains vowels only. If there is no vowel present in the string S, then return "No Vowel".
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints
1 <= |S| <= 10^{5}
The string should consist of only alphabets.

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Complete search

Starter code: #User function Template for python3

class Solution:
    def removeConsonants(self, s):
        #complete the function here


Solutions:
class Solution:

	def removeConsonants(self, s):
		p = ''
		a = 0
		for i in s:
			if i in ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u']:
				p += i
				a = a + 1
		if a == 0:
			return 'No Vowel'
		else:
			return p


class Solution:

	def removeConsonants(self, s):
		str1 = ''
		n = 'No Vowel'
		for i in range(len(s)):
			if s[i] == 'A' or s[i] == 'a':
				str1 = str1 + s[i]
			elif s[i] == 'E' or s[i] == 'e':
				str1 = str1 + s[i]
			elif s[i] == 'I' or s[i] == 'i':
				str1 = str1 + s[i]
			elif s[i] == 'O' or s[i] == 'o':
				str1 = str1 + s[i]
			elif s[i] == 'U' or s[i] == 'u':
				str1 = str1 + s[i]
			else:
				str1 = str1 + ''
		if len(str1) > 0:
			return str1
		else:
			return n


class Solution:

	def removeConsonants(self, s):
		k = ''
		for i in s:
			if i in 'aeiouAEIOU':
				k += i
		if len(k) == 0:
			return 'No Vowel'
		return k


class Solution:

	def removeConsonants(self, s):
		vowels = 'aeiouAEIOU'
		c = []
		for i in s:
			if i in vowels:
				c.append(i)
		if len(c) == 0:
			return 'No Vowel'
		else:
			c = ''.join(c)
		return c


class Solution:

	def removeConsonants(self, s):
		vowels = 'AaEeIiOoUu'
		i = 0
		while i < len(s):
			if s[i] not in vowels:
				s = s.replace(s[i], '')
				if len(s) <= 0:
					return 'No Vowel'
			else:
				i += 1
		if len(s) <= 0:
			return 'No Vowel'
		return s


class Solution:

	def removeConsonants(self, s):
		vowel = []
		cons = ''
		source = 'aeiouAEIOU'
		for i in s:
			if i in source:
				vowel.append(i)
		return ''.join(vowel) if vowel else 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		ans = ''
		vovel = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
		for i in s:
			if i in vovel:
				ans += i
		if len(ans) == 0:
			return 'No Vowel'
		else:
			return ans


class Solution:

	def removeConsonants(self, s):
		v = ''
		for i in s:
			if i in 'aeiouAEIOU':
				v += i
		if v == '':
			return 'No Vowel'
		else:
			return v


class Solution:

	def removeConsonants(self, s):
		l1 = []
		for i in s:
			j = i.lower()
			if j in {'a', 'e', 'i', 'o', 'u'}:
				l1.append(i)
		if l1 == []:
			return 'No Vowel'
		else:
			return ''.join(l1)


class Solution:

	def removeConsonants(self, s):
		result = ''
		for i in range(len(s)):
			if s[i] in ('a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'):
				result += s[i]
		if len(result) != 0:
			return result
		return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		l = []
		for i in s:
			if i == 'A' or i == 'E' or i == 'I' or (i == 'O') or (i == 'U') or (i == 'a') or (i == 'e') or (i == 'i') or (i == 'o') or (i == 'u'):
				l.append(i)
		s1 = ''.join(map(str, l))
		if len(s1) == 0:
			return 'No Vowel'
		else:
			return s1


class Solution:

	def removeConsonants(self, s):
		d = [i for i in s if i in 'aeiouAEIOU']
		return ''.join(d) if len(d) > 0 else 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		l = []
		v = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'O', 'I', 'U']
		for i in s:
			if i in v:
				l.append(i)
		if len(l) == 0:
			return 'No Vowel'
		else:
			r = ''.join(l)
			return r


class Solution:

	def removeConsonants(self, s):
		x = ''
		a = 'aeiou'
		b = a.upper()
		for i in s:
			if i in a or i in b:
				x += i
		if x == '':
			return 'No Vowel'
		else:
			return x


class Solution:

	def removeConsonants(self, s):
		s1 = ''
		for i in s:
			if i in 'aeiouAEIOU':
				s1 += i
		if s1 == '':
			return 'No Vowel'
		return s1


class Solution:

	def removeConsonants(self, s):
		res = []
		for i in range(len(s)):
			if s[i] in 'aeiouAEIOU':
				res.extend(s[i])
		if len(res) > 0:
			return ''.join(res)
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		a = ''
		for i in s:
			if i.lower() in 'aeiou':
				a += i
		return a if a else 'No Vowel'


class Solution:

	def isvowel(self, c):
		return c == 'a' or c == 'e' or c == 'i' or (c == 'o') or (c == 'u') or (c == 'A') or (c == 'E') or (c == 'I') or (c == 'O') or (c == 'U')

	def removeConsonants(self, s):
		x = ''
		for i in s:
			if self.isvowel(i):
				x += i
		if len(x) == 0:
			return 'No Vowel'
		return x


class Solution:

	def removeConsonants(self, s):
		x = ''
		lst = ['a', 'e', 'i', 'o', 'u']
		for i in s:
			if i.lower() in lst:
				x += i
		if len(x) == 0:
			return 'No Vowel'
		return x


class Solution:

	def removeConsonants(self, s):
		k = 'aeiouAEIOU'
		st = ''
		for i in range(len(s)):
			if s[i] in k:
				st = st + s[i]
		if st == '':
			return 'No Vowel'
		else:
			return st


class Solution:

	def removeConsonants(self, s):
		d = ''
		for i in s:
			l = i.lower()
			if l == 'a' or l == 'e' or l == 'i' or (l == 'u') or (l == 'o'):
				d += i
		if len(d) == 0:
			return 'No Vowel'
		else:
			return d


class Solution:

	def removeConsonants(self, s):
		consonants = set(['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z'])
		without_cons = [char for char in s if char not in consonants]
		if all((char in consonants for char in s)):
			return 'No Vowel'
		return ''.join(without_cons)


class Solution:

	def removeConsonants(self, s):
		ch = ''
		for i in s:
			if i in ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'U', 'O', 'I']:
				ch = ch + i
		if ch:
			return ch
		return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		vowels = ['a', 'e', 'i', 'o', 'u']
		ans = ''
		for i in s:
			if i.lower() in vowels:
				ans += i
		if ans == '':
			return 'No Vowel'
		return ans


class Solution:

	def removeConsonants(self, s):
		v = 'aeiouAEIOU'
		outStr = ''
		for i in s:
			if i in v:
				outStr += i
		if len(outStr) == 0:
			return 'No Vowel'
		else:
			return outStr


class Solution:

	def removeConsonants(self, s):
		a = list(s)
		count = 0
		length = len(a)
		vowels = ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']
		v = []
		for i in range(len(a)):
			if a[i] in vowels:
				v.append(a[i])
				flag = 1
			elif a[i] not in vowels:
				count += 1
		w = ''
		for j in range(len(v)):
			w += v[j]
		if count == length:
			return 'No Vowel'
		else:
			return w


class Solution:

	def removeConsonants(self, s):
		vowel = 'aeiouAEIOU'
		a = ''
		for i in s:
			if i in vowel:
				a += i
		if len(a) == 0:
			return 'No Vowel'
		return a


class Solution:

	def removeConsonants(self, s):
		str = ''
		R = 'No Vowel'
		vowels_of_list = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u']
		for index in s:
			if index in vowels_of_list:
				str += index
		if len(str) == 0:
			return R
		else:
			return str


class Solution:

	def removeConsonants(self, s):
		s1 = ''
		for ele in s:
			if ele == 'a' or ele == 'e' or ele == 'i' or (ele == 'o') or (ele == 'u') or (ele == 'A') or (ele == 'E') or (ele == 'I') or (ele == 'O') or (ele == 'U'):
				s1 += ele
		if len(s1) == 0:
			return 'No Vowel'
		else:
			return s1


class Solution:

	def removeConsonants(self, s):
		str2 = ''
		for i in range(len(s)):
			if s[i] in 'aeiouAEIOU':
				str2 += s[i]
		if len(str2) == 0:
			return 'No Vowel'
		else:
			return str2


class Solution:

	def removeConsonants(self, s):
		vowels = 'aeiouAEIOU'
		ans = ''
		for i in s:
			if i in vowels:
				ans += i
		if ans == '':
			return 'No Vowel'
		return ans


class Solution:

	def removeConsonants(self, s):
		vov = 'aeiouAEIOU'
		new = ''
		for i in s:
			if i in vov:
				new += i
		if len(new) == 0:
			return 'No Vowel'
		else:
			return new


class Solution:

	def removeConsonants(self, s):
		k = ''
		vow = ['a', 'e', 'i', 'o', 'u']
		for i in s:
			r = i.lower()
			if r in vow:
				k += i
		if k == '':
			return 'No Vowel'
		return k


class Solution:

	def removeConsonants(self, s):
		a = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
		i = 0
		s1 = ''
		while i < len(s):
			if s[i] in a:
				s1 += s[i]
			i += 1
		return s1 if len(s1) != 0 else 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		li = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
		str = ''
		for i in s:
			if i in li:
				str += i
		if str == '':
			return 'No Vowel'
		else:
			return str


class Solution:

	def removeConsonants(self, s):
		vovel = 'aeiouAEIOU'
		result = ''
		for i in s:
			if i in vovel:
				result += i
		if len(result) > 0:
			return result
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		list1 = []
		for i in s:
			if i == 'a' or i == 'e' or i == 'i' or (i == 'o') or (i == 'u') or (i == 'A') or (i == 'E') or (i == 'I') or (i == 'O') or (i == 'U'):
				list1.append(i)
		if len(list1) > 0:
			return ''.join(list1)
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		st = ''
		for i in s:
			if i.lower() in ['a', 'e', 'i', 'o', 'u']:
				st += i
		if st == '':
			return 'No Vowel'
		else:
			return st


class Solution:

	def removeConsonants(self, s):
		b = ['A', 'E', 'I', 'O', 'U']
		ans = ''
		for i in s:
			if i.upper() in b:
				ans += i
		if len(ans) == 0:
			return 'No Vowel'
		return ans


class Solution:

	def removeConsonants(self, s):
		temp = ''
		for i in s:
			if i in 'AEIOU' or i in 'aeiou':
				temp += i
		if len(temp) > 0:
			return temp
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		vowels = 'aeoui'
		vowels += vowels.upper()
		res = ''
		for i in s:
			if i in vowels:
				res += i
		if len(res) > 0:
			return res
		return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		a = []
		for i in s:
			if i in 'aeiouAEIOU':
				a.append(i)
		m = ''.join(a)
		if len(m) == 0:
			return 'No Vowel'
		else:
			return m


class Solution:

	def removeConsonants(self, s):
		l = ''
		k = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
		a = list(s)
		for i in range(len(a)):
			if a[i] in k:
				l += a[i]
			else:
				continue
		if len(l) >= 1:
			return l
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		v = 'aeiouAEIOU'
		a = ''
		for i in s:
			if i in v:
				a += i
		if len(a) >= 1:
			return a
		return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		vowels = 'aeiou'
		v = ''
		for i in s:
			temp = i.lower()
			if temp in vowels:
				v += i
		if len(v) < 1:
			return 'No Vowel'
		else:
			return v


import re

class Solution:

	def removeConsonants(self, s):
		pat = re.findall('[aeiouAEIOU]+', s)
		if pat:
			return ''.join(pat)
		return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		j = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
		c = []
		for i in s:
			if i in j:
				c.append(i)
		return ''.join(c) or 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		x = 'aeiouAEIOU'
		ans = ''
		for i in s:
			if i in x:
				ans += i
		return ans if len(ans) != 0 else 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		vowel_list = ['a', 'e', 'i', 'o', 'u']
		response_str = ''
		for char in s:
			if char.lower() in vowel_list:
				response_str = response_str + char
		if response_str:
			return response_str
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		v = 'aeiouAEIOU'
		newstring = ''
		for i in s:
			if i in v:
				newstring += i
		if len(newstring):
			return newstring
		return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		temp = 'aeiouEIOUA'
		ans = ''
		for i in s:
			if i in temp:
				ans = ans + i
		if len(ans) == 0:
			return 'No Vowel'
		return ans


class Solution:

	def removeConsonants(self, s):
		d = ''
		a = 'AEIOUaeiou'
		for i in s:
			if i in a:
				d = d + i
		if len(d) == 0:
			return 'No Vowel'
		else:
			return d


class Solution:

	def removeConsonants(self, s):
		if 'a' not in s and 'e' not in s and ('i' not in s) and ('o' not in s) and ('u' not in s) and ('A' not in s) and ('E' not in s) and ('I' not in s) and ('O' not in s) and ('U' not in s):
			return 'No Vowel'
		ans = ''
		for i in s:
			if i == 'a' or i == 'e' or i == 'i' or (i == 'o') or (i == 'u') or (i == 'A') or (i == 'E') or (i == 'I') or (i == 'O') or (i == 'U'):
				ans += i
		return ans


class Solution:

	def removeConsonants(self, S):
		consonants = 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ'
		new_str = ''
		for i in range(len(S)):
			if S[i] not in consonants:
				new_str += S[i]
		if len(new_str) == 0:
			return 'No Vowel'
		else:
			return new_str


class Solution:

	def removeConsonants(self, s):
		c = ''
		v = 'aeiouAEIOU'
		l = list(s)
		for i in l:
			if i in v:
				c += i
		if len(c) > 0:
			return c
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		new = ''
		vow = 'aeiou'
		for i in s:
			if i.lower() in vow:
				new += i
		if new:
			return new
		else:
			return 'No Vowel'


class Solution:

	def removeConsonants(self, s):
		x = 'aeiouAEIOU'
		y = ''
		for i in range(len(s)):
			if s[i] in x:
				y = y + s[i]
		if y == '':
			return 'No Vowel'
		else:
			return y


class Solution:

	def removeConsonants(self, s):
		st = ''
		for i in range(len(s)):
			if s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or (s[i] == 'o') or (s[i] == 'u') or (s[i] == 'A') or (s[i] == 'E') or (s[i] == 'I') or (s[i] == 'O') or (s[i] == 'U'):
				st += s[i]
		if st == '':
			return 'No Vowel'
		else:
			return st


class Solution:

	def removeConsonants(self, s):
		vowels = 'aeiouAEIOU'
		str = ''
		for x in s:
			if x in vowels:
				str += x
		if str == '':
			return 'No Vowel'
		else:
			return str


class Solution:

	def removeConsonants(self, s):
		k = ''
		m = 'No Vowel'
		x = ['a', 'A', 'e', 'E', 'i', 'I', 'O', 'o', 'U', 'u']
		for i in s:
			if i in x:
				k = k + i
		if len(k) != 0:
			return k
		else:
			return m


class Solution:

	def removeConsonants(self, s):
		str2 = ''
		vovels = 'aeiouAEIOU'
		for i in s:
			if i in vovels:
				str2 += i
		if len(str2) < 1:
			return 'No Vowel'
		else:
			return str2


class Solution:

	def removeConsonants(self, s):
		vowels = 'aeiouAEIOU'
		new_string = ''
		for i in s:
			if i in vowels:
				new_string += i
		if len(new_string) > 0:
			return new_string
		else:
			return 'No Vowel'