Question: In Python 3.5 or newest release Imagine that the most of the functions that we have been using to process lists in Python do not
In Python 3.5 or newest release
Imagine that the most of the functions that we have been using to process lists in Python do not exist. For the problems below you are not allowed to use any list methods (append, remove, insert, etc) or certain core Python functions specified in each problem. You may, however, use your own custom-written functions to solve these problems (i.e. if you find that your listlen() function would be useful in writing another function you are welcome to use it). Given these restrictions, write a series of functions that do the following:
6. Write a new function called "listremove" based on the following IPO
# function: listremove # INPUT: a list and a data element (can be a string, # float, Boolean or int) # PROCESSING: removes all occurrences of the supplied # data element from the list. You can assume # that the data element is present in the list # somewhere. # OUTPUT: return a new copy of the list with the # desired element removed
Make sure that you DO NOT use any list methods, such as the "remove" method, or the "del" command in your program. Note that your original list should not change when you run this function. Here is a sample running of this program:
mylist = [10, 20, 30] x = listremove(mylist, 20) print (x) print (mylist) >> [10, 30] >> [10, 20, 30]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
