ex06 part 2 ok

This commit is contained in:
hugogogo
2025-10-26 20:57:53 +01:00
parent 2e1edf72b2
commit 1cf9f29496

View File

@@ -0,0 +1,39 @@
from ft_filter import ft_filter
def get_args(argv: list[str]) -> dict[str, int]:
"""check and return arguments"""
error_msg = "the arguments are bad"
assert len(argv) == 3, error_msg
try:
msg_len = int(argv[2])
except ValueError:
raise AssertionError(error_msg)
return {"text": argv[1], "len": msg_len}
def main(argv: list[str]):
"""filter small words in string"""
try:
args = get_args(argv)
except AssertionError as err:
print("AssertionError:", err)
return
text = args["text"]
maxlen = args["len"]
words = [word for word in text.split()]
filter_words = list(ft_filter(lambda word: len(word) > maxlen, words))
print(filter_words)
if __name__ == "__main__":
import sys
main(sys.argv)