+ 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']
2 odpowiedzi
+ 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))
+ 1
Thanks Tibor :)