#--------------------------------------------------- # Function name: unsortedSearch # Input: list -> the list of unsorted elements # searchItem -> the search value # Output: the index where the search value was found in the list, # or -1, if the search value is not found def unsortedSearch (list, searchItem): index = 0 while (index < len(list)): if (list[index] == searchItem): return index index = index + 1 return -1 #--------------------------------------------------- # Main program: # names = ["Sue", "Mark", "William", "Cora", "Beth", "Tyler", "Ann", "June", "David"] # names = ["Steve", "Garrett", "Danyu", "Krystal", "Chau", "Winnie", "Peter"] print print "Unsorted list is", names print searchVal = raw_input("What name do you want to search for? ") print found = unsortedSearch (names, searchVal) if (found != -1): print "The search string was found in list 'names' at index", found else: print "The search string was not found in list 'names'" print