Python Survey data practical | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python Survey data practical

I seriously need help here Given a list of string representing user answers, write a program that uses the filter() function and lambda expression to create a new list that excludes any empty strings. then display the new cleaned list of answers.

24th Feb 2024, 11:11 AM
Musa Suso
Musa Suso - avatar
3 Answers
+ 5
musa suso , in the python tutorials `python intermediate` or `python developer` you can find a sample of how we can use filter with a lambda functiom: `... - functional programming - map and filter` if you have not done any of these tutorials, you can start learning and practicing from them.
24th Feb 2024, 9:17 PM
Lothar
Lothar - avatar
+ 3
Would you provide the input and your code attempted?
24th Feb 2024, 2:21 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
I just came here looking for help on this one but with a bit of tinkering I got mine working. Here is my answer. user_answers = ["Yes", "", "No", "", "Maybe", "", "Yes"] # Create a new list without empty answers # using filter with a lambda expression filtered_answers = list(filter(lambda name: name != "", user_answers)) # Display the cleaned list of answers print(filtered_answers)
26th Feb 2024, 9:11 AM
Stephen O'Neil
Stephen O'Neil - avatar