-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilterstring.py
More file actions
42 lines (34 loc) · 1.32 KB
/
Copy pathfilterstring.py
File metadata and controls
42 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
from ft_filter import ft_filter as my_filter
def compare_len(len_max):
"""Function which compare each len of each word with lambda and len_max.
Lambda iter on words."""
return lambda word: len(word) > len_max
def main():
"""Fisrt check validity of each arguments.
Split argv[1] to extract each words.
Check validity of each words and reassign `words` with valid ones
Filtered list is created with ft_filter() -> list comprehension.
Print the filtered list.
"""
try:
if len(sys.argv) != 3:
raise AssertionError("AssertionError: the arguments or bad")
if not isinstance(sys.argv[1], str):
raise AssertionError("AssertionError: the arguments or bad")
if not sys.argv[2].isdigit():
raise AssertionError("AssertionError: the arguments or bad")
len_max = int(sys.argv[2])
if len_max < 0:
raise AssertionError("AssertionError: the arguments or bad")
words = sys.argv[1].split()
# comprehension list here - not yield !
words = [word for word in words if word.isalpha()]
filtered = my_filter(compare_len((len_max)), words)
print(list(filtered))
except AssertionError as error:
print(error)
sys.exit(1)
return 0
if __name__ == "__main__":
main()