# https://www.facebook.com/groups/pythonsnake/ """ Write function that takes two args: list of strings and a prefix (string). The function should iterate over the list and find all strings which start with the prefix, then return list of such strings """ def return_prefixed_strings(strings, prefix): results = [] for string in strings: if string.startswith(prefix): results.append(string) return results def test_return_prefixed_strings(): test_cases = [ ((["Jamal", "Jaden", "Fahad", "Murtaza"], "Ja"), ["Jamal", "Jaden"]), ((["Jamal", "Jaden", "Fahad", "Murtaza"],"Fa"), ["Fahad"]) ] for (args, answer) in test_cases: result = return_prefixed_strings(*args) # print "Running Test with data:", args, "gave = ", result if result != answer: print("\x1b[0;30;41m" + "Test with data:", args, "failed" + "\x1b[0m") else: print("\x1b[6;30;42m" + "Test with data:", args, "passed" + "\x1b[0m") test_return_prefixed_strings()