Python question, please use a docstring and have comments throughout the code Write a function makeAllStrings() that takes a 2D list (a list of lists) as a parameter and modifies it. It changes the list so that all non-string objects in the list are replaced with an empty string. Strings in the list are left unchanged, so that a list containing only strings would not be modified. The empty list should also not be modified. The function returns the number of changes made by the function in the list. Recall that you can determine if a variable var holds a string by writing type(var) == str. Please write the condition you want and not the opposite of it. Use nested for loop pattern and if-else. Remember to return the count not the list. Remember you can change the value of an item in a list by using the index operator. Below are some sample executions of the function. Use the nested loop and an if-elif in the solution. Don’t forget to include the docstring and comments. Copy and paste or screen shot the code and the nine test cases shown below in your submission.   >>> lst1 = [['one','two'],[3, 'four'],[5.5, 'six'],[7, 8.8]] # list input >>> makeAllStrings(lst1) # run function with this parameter 4 >>> lst1 # show that list was modified [['one', 'two'], ['', 'four'], ['', 'six'], ['', '']] >>> makeAllStrings(lst1) # show that the list is all string now 0 >>> lst1 [['one', 'two'], ['', 'four'], ['', 'six'], ['', '']] >>> lst2 = [['Lillian',2,9.9],['Cathrine',7,16.8],['Thersa',12,10.5]] >>> makeAllStrings(lst2) 6 >>> lst2 [['Lillian', '', ''], ['Catharine', '', ''], ['Teresa', '', '']] >>> lst3=[[1,2,3,4,5],['one','two','three'],[1.1,2.2],['four','five','six','seven'],[10]] >>> makeAllStrings(lst3) 8 >>> lst3 [['', '', '', '', ''], ['one', 'two', 'three'], ['', ''], ['four', 'five', 'six', 'seven'], ['']] >>> lst4 = [] >>> makeAllStrings(lst4) 0 >>> lst4 []

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python question, please use a docstring and have comments throughout the code

  • Write a function makeAllStrings() that takes a 2D list (a list of lists) as a parameter and modifies it. It changes the list so that all non-string objects in the list are replaced with an empty string. Strings in the list are left unchanged, so that a list containing only strings would not be modified. The empty list should also not be modified. The function returns the number of changes made by the function in the list. Recall that you can determine if a variable var holds a string by writing type(var) == str. Please write the condition you want and not the opposite of it. Use nested for loop pattern and if-else. Remember to return the count not the list. Remember you can change the value of an item in a list by using the index operator. Below are some sample executions of the function. Use the nested loop and an if-elif in the solution. Don’t forget to include the docstring and comments. Copy and paste or screen shot the code and the nine test cases shown below in your submission.

 

>>> lst1 = [['one','two'],[3, 'four'],[5.5, 'six'],[7, 8.8]] # list input

>>> makeAllStrings(lst1) # run function with this parameter

4

>>> lst1 # show that list was modified

[['one', 'two'], ['', 'four'], ['', 'six'], ['', '']]

>>> makeAllStrings(lst1) # show that the list is all string now

0

>>> lst1

[['one', 'two'], ['', 'four'], ['', 'six'], ['', '']]

>>> lst2 = [['Lillian',2,9.9],['Cathrine',7,16.8],['Thersa',12,10.5]]

>>> makeAllStrings(lst2)

6

>>> lst2

[['Lillian', '', ''], ['Catharine', '', ''], ['Teresa', '', '']]

>>> lst3=[[1,2,3,4,5],['one','two','three'],[1.1,2.2],['four','five','six','seven'],[10]]

>>> makeAllStrings(lst3)

8

>>> lst3

[['', '', '', '', ''], ['one', 'two', 'three'], ['', ''], ['four', 'five', 'six', 'seven'], ['']]

>>> lst4 = []

>>> makeAllStrings(lst4)

0

>>> lst4

[]

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education