
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- 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
- How do we extract all the words start with a vowel and length equal to n in java?
- Python program to extract characters in given range from a string list
- Python program to find word score from list of words
- Extract digits from Tuple list Python
- Python Program to Extract Strings with at least given number of characters from other list
- Python – Extract element from a list succeeded by K
- Python – Extract elements from Ranges in List
- Extract numbers from list of strings in Python
- Python program to extract only the numbers from a list which have some specific digits
- Python program to extract rows from Matrix that has distinct data types
- Regex in Python to put spaces between words starting with capital letters

Advertisements