/ Published in: Python
Expand |
Embed | Plain Text
# 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) False >>> contains_iterative(1, foo_lst) True """ found = False while (not rest(l) == None) and (not found): if first(l) == n: found = True else: l = rest(l) return found
You need to login to post a comment.
