Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON 2) Write a program to filter out all empty strings within a list of strings. For this exercise, write a function clean_list( list1)

PYTHON image text in transcribed
2) Write a program to filter out all empty "" strings within a list of strings. For this exercise, write a function clean_list( list1) where list1 is the list with many "" empty strings. This function returns a list without any "" components. lst1=["Tom", "", "Dick", "Harry","", "Here", "", "There", "", "Everywhere"] In the clean_list(1st1) function: Create a new list[] Use a while loop to iterate the list: If the item is ! "": Append it to the new list[] Increment index Return the new list. results; ['Tom', ", 'Dick', 'Harry', ", 'Here', ", 'There', ", 'Everywhere'] ['Tom', 'Dick', 'Harry', 'Here', 'There', 'Everywhere'] 3) This time instead of removing all the "" empty strings, the program breaks off and stop the first encounter of "". Result: ['Tom', ", 'Dick', 'Harry', ", 'Here', ", 'There', ", 'Everywhere'] ['Tom']

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions