Python OOPs


Examples


Others


Filter vowels from String using filter() method in Python


Write a Python program to filter all vowels from string using filter() method in Python.

pgm.py
a=list("sample")
def vowel(x):
    v=('a','e','i','o','u')
    return x in v

b=list(filter(vowel,a))
print("Vowels : ",b)
print("No of Vowels : ",len(b))
Output:
Vowels :  ['a', 'e']
No of Vowels :  2