

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program that extract words starting with Vowel From A list
When it is required to extract words starting with vowel from a list, a simple iteration, a flag value and the ‘startswith’ method are used.
Below is a demonstration of the same −
Example:
my_list = ["abc", "phy", "and", "okay", "educate", "learn", "code"] print("The list is :") print(my_list) my_result = [] my_vowel = "aeiou" print("The vowels are ") print(my_vowel) for index in my_list: my_flag = False for element in my_vowel: if index.startswith(element): my_flag = True break if my_flag: my_result.append(index) print("The result is :") print(my_result)
Output:
The list is : ['abc', 'phy', 'and', 'okay', 'educate', 'learn', 'code'] The vowels are aeiou The result is : ['abc', 'and', 'okay', 'educate']
Explanation
A list is defined and displayed on the console.
An empty list is created.
The vowel string is defined and displayed on the console.
The list is iterated over, and the flag is assigned to Boolean ‘False’.
If the first element of each string begins with characters in the vowels list, the Boolean flag value is set to ‘True’.
This is checked using the ‘startswith’ method.
The control breaks out of the loop.
If the value of Boolean flag is ‘True’, the element is appended to the empty list.
This is the output that is displayed on the console.
- Related Questions & Answers
- Python Program to accept string starting with vowel
- Python program to extract Keywords from a list
- Python Program to Create a Dictionary with Key as First Character and Value as Words Starting with that Character
- Python Program to Extract Elements from a List in a Set
- Extract digits from Tuple list Python
- How do we extract all the words start with a vowel and length equal to n in java?
- Python program to find word score from list of words
- Python program to extract characters in given range from a string list
- Python program to extract rows from Matrix that has distinct data types
- Regex in Python to put spaces between words starting with capital letters
- How to extract words from a string vector in R?
- Python Program to Extract Strings with at least given number of characters from other list
- Python – Extract element from a list succeeded by K
- c# Put spaces between words starting with capital letters
- Extract numbers from list of strings in Python
Advertisements