# Here are a variety of different solutions to the find(s,c) # problem by various students and one teacher... ############ CYRUS CURSETJEE: def cfind(s,c): # Cyrus if s[0] == c[-1]: return len(c) - 1 if len(s) == 1: return -1 return cfind(s[1:],s[0]+c) ############# Ivan Wei def ifind(s, c): # Ivan if not s: return -1 if s[0] == c: return 0 result = ifind(s[1:], c) if result == -1: return -1 return 1 + result ######### Deven Maheshwari + Maxwell Zen def find(s,c): #Deven + Maxwell try: if s[0] == c: return 0 else: if find(s[1:],c) == -1: return -1 return find(s[1:],c)+1 except: return -1 ############ Gregory Wickham def gfind(s,c): # Gregory if s == '': return -1 if s[-1] == c: return len(s)-1 return gfind(s[:-1],c) ############ Mr. Brooks def pbfind_helper(s,c,n): # Mr. Brooks if s == '': return -1 if s[0] == c: return n return pbfind_helper(s[1:],c,n+1) def pbfind(s,c): return pbfind_helper(s,c,0) ############# A different version of Reverse(L), reversing 2 elements # each time... Alvin Li def ireverse(L): # Alvin if len(L) <= 1: return L return [L[-1]] + ireverse(L[1:-1]) + [L[0]]