Question: Lists & Tuples in Python Use a function to help with list management Using functions, you can automate some steps involved in list management. For

Lists & Tuples in Python

Use a function to help with list management

Using functions, you can automate some steps involved in list management. For this lab, you will create a single function that allows for appending items to a list or removing items from a list. The list will also be sorted.

Program Requirements:

1. List Function

Create a function that accepts three parameters, a list, an item to be added or removed from the list, and a third optional parameter that specifies if the item is to be removed or added to the list.

Function Requirements:

*If the item is already found in the list, AND the parameter to delete the item from the list is set to True, remove the item from the list.

*If the item is already found in the list, AND the parameter to delete the item from the list is set to False, no change will be made to the list.

*If the item is NOT found in the list, regardless of the parameter to delete the item, add the item to the list.

*In ALL cases, your function must sort the updated list after the item was added, removed, or no change was made to the list.

2. Return a Tuple

The function must return a tuple with two items in it.

Tuple Requirements:

*The tuple contains the list as one of its items.

*The tuple contains the length of the list as its other item. This will be an integer.

3. Include a Docstring

Include a simple docstring at the beginning of your function, describing your function and its parameters.

4. Main Body of Program

After you create your function, write some code to test the implementation of it.

1. Create a list with three items of your choice.

2. Use this list as an argument in your function:

A. Use your function to add an item to your list.

B. Use your function to remove an item from your list.

C. Use your function in the third case, where your item exists in the list already, and no change is performed on the list.

3. For the three tests above, print a statement that describes the output of your function, like this:

EXAMPLE: My list is and has elements.

REMINDER: Run your code and make sure it works as intended.

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!