Compare commits
2 Commits
6f83006187
...
2e1edf72b2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e1edf72b2 | ||
|
|
49461a0b25 |
@@ -22,15 +22,15 @@ def main(argv: list[str]):
|
||||
print("AssertionError:", err)
|
||||
return
|
||||
|
||||
|
||||
char_count = len(msg)
|
||||
print("The text contains", char_count,"characters:")
|
||||
print("The text contains", char_count, "characters:")
|
||||
|
||||
# filter() https://docs.python.org/3.10/library/functions.html#filter
|
||||
upper_count = len(list(filter(str.isupper, msg)))
|
||||
print(upper_count, "upper letters")
|
||||
|
||||
# generator expressions https://docs.python.org/3.10/reference/expressions.html#generator-expressions
|
||||
# generator expressions
|
||||
# https://docs.python.org/3.10/reference/expressions.html#generator-expressions
|
||||
lower_count = sum(1 for char in msg if char.islower())
|
||||
print(lower_count, "lower letters")
|
||||
|
||||
@@ -39,11 +39,13 @@ def main(argv: list[str]):
|
||||
punctuation_count = sum(1 for char in msg if char in punctuation)
|
||||
print(punctuation_count, "punctuation marks")
|
||||
|
||||
# array.count() https://docs.python.org/3.10/library/array.html?highlight=count#array.array.count
|
||||
# array.count()
|
||||
# https://docs.python.org/3.10/library/array.html?highlight=count#array.array.count
|
||||
space_count = msg.count(" ") + msg.count("\n")
|
||||
print(space_count, "spaces")
|
||||
|
||||
# list comprehension https://docs.python.org/3.10/tutorial/datastructures.html#list-comprehensions
|
||||
# list comprehension
|
||||
# https://docs.python.org/3.10/tutorial/datastructures.html#list-comprehensions
|
||||
digits_count = len([char for char in msg if char.isdigit()])
|
||||
print(digits_count, "digits")
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ def ft_filter(function, iterable):
|
||||
Return an iterator yielding those items of iterable for which function(item)
|
||||
is true. If function is None, return the items that are true."""
|
||||
|
||||
# iter https://docs.python.org/3.10/library/functions.html?highlight=iter#iter
|
||||
# iter
|
||||
# https://docs.python.org/3.10/library/functions.html?highlight=iter#iter
|
||||
if function is None:
|
||||
return iter([item for item in iterable if item])
|
||||
else:
|
||||
|
||||
@@ -16,4 +16,4 @@ print("- 3 filter :", list(filter(None, msg)))
|
||||
print(" ft_filter :", list(ft_filter(None, msg)))
|
||||
|
||||
print("- 4 filter :", list(filter(str.isupper, msg)))
|
||||
print(" ft_filter :", list(ft_filter(str.isupper, msg)))
|
||||
print(" ft_filter :", list(ft_filter(str.isupper, msg)))
|
||||
|
||||
Reference in New Issue
Block a user