def multiSearch(lst, val): """ Return a list of (the positions of) all occurrences of val in lst. >>> testlist = [5, 2, 9, 8, 9, 2, 6, 0, 9, 1] >>> multiSearch(testlist, 9) [2, 4, 8] >>> multiSearch(testlist, 4) [] >>> multiSearch(testlist, 0) [7] """ found = [] for pos in range(len(lst)): if lst[pos]==val: found.append(pos) return found # Just because we haven't seen it before... this code # uses the doctest module to check the test cases in # the function's docstring. If they match reality, # the script produces no output. def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test() # Try introducing an error into the docstring above # and run this program to see the output you get if # one of the tests fails.