0
python filter() function
# how can i do this with the python filter() function # i have spent way to much time on this already.. # i don't understand how to use filter() to Iterate a list?? names = ["David", "John", "Annabelle", "Johnathan", "Veronica"] result = [] for word in names: if len(word) >5: result.append(word) print(result)
4 odpowiedzi
+ 4
res = list(filter(lambda x: len(x) > 5, names))
print(res)
+ 2
ChaoticDawg:
omg thank you i knew it was something like that but for the life of me i couldn't figure it out i tried len() every way i could think of
0
If you can convert the condition len(word) > 5 into a function, then you would be half done.