- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
-
- 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 Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Python Program to print element with maximum vowels from a List
When it is required to print element with maximum vowels from a list, a list comprehension is used.
Below is a demonstration of the same
my_list = ["this", "week", "is", "going", "great"] print("The list is :") print(my_list) my_result = "" max_length = 0 for element in my_list: vowel_length = len([element for element in element if element in ['a', 'e', 'o', 'u', 'i']]) if vowel_length > max_length: max_length = vowel_length my_result = element print("The result is :") print(my_result)
The list is : ['this', 'week', 'is', 'going', 'great'] The result is : k
- A list of strings is defined and is displayed on the console.
- An empty string variable is created.
- A variable defined as ‘max_length’ is defined and is ‘0’ is assigned to it.
- The list is iterated over, and the list comprehension is used to check if a vowel is present.
- This is converted to a list, and its length is assigned to a variable.
- If length of this list is greater than the ‘max_length’, they are equated.
- The element is assigned as the output.
- This is displayed as output on the console.
- Related Articles
- How to find the element from a Python list with a maximum value?
- Python Program to print unique values from a list
- Python program to print duplicates from a list of integers?
- Program to find maximum XOR with an element from array in Python
- Python Program to Get Minimum and Maximum from a List
- Python Program to print a specific number of rows with Maximum Sum
- Python program to remove row with custom list element
- Python Program to Print Nth Node from the last of a Linked List
- Python Program to Test if string contains element from list
- C# program to print unique values from a list
- Java program to print unique values from a list
- Java Program to remove an element from List with ListIterator
- Python program to print all sublists of a list.
- Python program to print even numbers in a list
- Python program to print negative numbers in a list