When it is required to accept a string that starts with a vowel, a ‘startswith’ function is used to check if the string begins with a specific character (vowel) or not.
Example
Below is a demonstration of the same
my_list = ["Hi", "there", "how", "are", "u", "doing"]
print("The list is : ")
print(my_list)
my_result = []
vowel = "aeiou"
for sub in my_list:
flag = False
for letter in vowel:
if sub.startswith(letter):
flag = True
break
if flag:
my_result.append(sub)
print("The resultant string is : ")
print(my_result)Output
The list is : ["Hi", "there", "how", "are", "u", "doing"] The resultant string is : ['are', 'u']
Explanation
A list is defined and is displayed on the console.
An empty list is defined.
The vowels are defined in a string.
The list is iterated over and a ‘flag’ variable is assigned to False.
The letters in the string are compared to the vowel string.
The ‘startswith’ method is used to check if a string in the list begins with a vowel.
If yes, it is displayed on the console.