/ Published in: Python
- # Question 0 - Iterative Version
- def contains_iterative(n, l):
- """Returns True if n is in rlist l and False otherwise.
- >>> foo_lst = make_rlist(1, make_rlist(2, make_rlist(3, empty_rlist)))
- >>> contains_iterative(5, foo_lst)
- >>> contains_iterative(1, foo_lst)
- found = False
- while (not rest(l) == None) and (not found):
- if first(l) == n:
- found = True
- l = rest(l)
- return found
You need to login to post a comment.