CMPT 120 LECTURE MIDTERM 2 SOLUTIONS

lens2 return false for i in rangelens1 if s1 s2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for the empty list . You may not use the Python expression, x1==x2, in your answer. Examples: equals(, ) = True equals(, [2]) = False equals([2], [2]) = True equals([2, 3], [2]) = False def equals(s1, s2): if (len(s1) != len(s2)): return False for i in range(len(s1)): if (s1 != s2): return False return True 13. Write the function, member(x, lst), which returns True if x is an element in list lst and False otherwise. For examples: member(1, [0, 1, 2]) member(1, ) = = True False def member(x, lst): for y in lst: if...
View Full Document

This document was uploaded on 03/18/2014 for the course CMPT 120 at Simon Fraser.

Ask a homework question - tutors are online