< Back

Post Lab 12

Contains

One thing that will help you in creating recursive functions in the future is rewriting functions you have previously written, in a recursive manner. In this case, you are going to write a function for linear search, recursively.

Details

Create a file membership.py, and write a function contains(a_list, item) in this file. This function should return True if item is in a_list, and False otherwise.

You are not allowed to use any loops, or the in operator for this exercise.

Example

>>> contains([1, 2, 3, 4], 4)
True
>>> contains([1, 2, 3, 4], 3)
True
>>> contains([1, 2, 3, 4], 5)
False
>>> contains(['a', 'b', 'c'], 'b')
True
>>> contains(['a', 'b', 'c'], 'd')
False

Submission

Please submit your Python file to inquire by the beginning of class on Monday, Feb. 24th