# L-27 MCS 260 Mon 29 Oct 2007 : useassert.py # # def searchlist ( L , i ): """ Searches a list L for the integer i, returning -1 if the item does not belong to the list, or else returning the position of the item in the list. Preconditions: isinstance(L,list) and isinstance(i,int) Postconditions: searchlist(L,i) == -1 or searchlist(L,i) == p and L[p] == i """ assert isinstance(L,list) assert isinstance(i,int) p = -1 for k in range(0,len(L)): if L[k] == i: p = k break assert p == -1 or (p == k and L[k] == i) return p