Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If our data is messy, which it often is, then when we are collecting values from a given column into a list, some values will

image text in transcribed
If our data is messy, which it often is, then when we are collecting values from a given column into a list, some values will be None. if we want to do any numerical analysis of this data, then we may want to filter out the None values. This is not always wise, because that filtering may distort the results of the analysis in ways we don't anticipate, but it is useful to have the option. Define a function named remove None() that filters a list to remove None values, returning the filtered list . It has one parameter a list of values, some of which may be the None value. . The function should return a new list, containing all of the values from the provided list that are not None [ ]: # Define the r None() function here Tests Executing the cell below will run some tests on the remove_None() function you First two expected test outputs define above. It passes a variety of lists to the function The expected return first two are shown here, and you should think about what the others should be to verifty that your function is passingall of the tests list: [1, 2, None, 3] return value: [1, 2, 3] list: ['This, "list, 'has no, "None', "values. ] return value: ['This', 'list, 'has, 'no', None', 'values.' [ ] : :# Tests for remove--() [do not modify] test list1 - [, 2, None, 3 test list 2 ["This", "list", "has", "no", "None", "values." test list 3 [None, 1, None, 2, None, 3, 4, None] test_list 4 [None, None, None] test list 5 [ test list_6 [1, 2, 3] for test_list in [test_list 1, test_list 2, test_1ist 3, test_list 4, test_list 5, test_list 6]: ret remove None(test list) print("list: (Nnreturn value: (1n".format (repr(test_list), ret)) 12:37 AM If our data is messy, which it often is, then when we are collecting values from a given column into a list, some values will be None. if we want to do any numerical analysis of this data, then we may want to filter out the None values. This is not always wise, because that filtering may distort the results of the analysis in ways we don't anticipate, but it is useful to have the option. Define a function named remove None() that filters a list to remove None values, returning the filtered list . It has one parameter a list of values, some of which may be the None value. . The function should return a new list, containing all of the values from the provided list that are not None [ ]: # Define the r None() function here Tests Executing the cell below will run some tests on the remove_None() function you First two expected test outputs define above. It passes a variety of lists to the function The expected return first two are shown here, and you should think about what the others should be to verifty that your function is passingall of the tests list: [1, 2, None, 3] return value: [1, 2, 3] list: ['This, "list, 'has no, "None', "values. ] return value: ['This', 'list, 'has, 'no', None', 'values.' [ ] : :# Tests for remove--() [do not modify] test list1 - [, 2, None, 3 test list 2 ["This", "list", "has", "no", "None", "values." test list 3 [None, 1, None, 2, None, 3, 4, None] test_list 4 [None, None, None] test list 5 [ test list_6 [1, 2, 3] for test_list in [test_list 1, test_list 2, test_1ist 3, test_list 4, test_list 5, test_list 6]: ret remove None(test list) print("list: (Nnreturn value: (1n".format (repr(test_list), ret)) 12:37 AM

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

More Books

Students also viewed these Databases questions