+ 1

not able to get correct ans

letters = ['a', 'b', 'd', 'e', 'i', 'j', 'o'] vowles= list(filter(lambda x:(True if x in letters else False),letters)) print(vowles) # Exact ans need to be ['a','e','i','o','u']

24th Apr 2022, 4:20 AM
Amol Bhandekar
Amol Bhandekar - avatar
2 Respuestas
+ 5
Your code is listing all the letters that were in the original list, because each letter meets the condition you defined in filter, that it must be included in the letters list. Your code never mentioned the actual vowels that you want to filter out. Try it like this: vowles = list(filter(lambda x:(True if x in ['a','e','i','o','u'] else False), letters)) Or even more simplified, this works too: vowles = list(filter(lambda x: x in 'aeiou', letters))
24th Apr 2022, 4:31 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thanks Tibor :)
24th Apr 2022, 4:49 AM
Amol Bhandekar
Amol Bhandekar - avatar