Question: Write a recursive function bag_to_set that takes a list as a parameter and returns a new list in which the values that were in the

Write a recursive function bag_to_set that takes a list as a parameter and returns a new list in which the values that were in the old list appear only once in the new list (the order should be preserved). Sample data:

Old list: [4, 5, 3, 4, 5, 2, 2, 4] New list: [4, 5, 3, 2] 

The function signature is:

def bag_to_set(bag): """ ------------------------------------------------------- Copies elements of a bag to a set. Use: new_set = bag_to_set(bag) ------------------------------------------------------- Parameters: bag - a list of values (list) Returns: new_set - containing one each of the elements in bag (list) ------------------------------------------------------- """ 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!