-
-
Save nguyendo24/82e613fa3e47d6e1a6f398b8a6eeb3d2 to your computer and use it in GitHub Desktop.
Revisions
-
fahdi created this gist
Aug 11, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ # 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()