Compare commits
2 Commits
6f83006187
...
2e1edf72b2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e1edf72b2 | ||
|
|
49461a0b25 |
@@ -22,15 +22,15 @@ def main(argv: list[str]):
|
|||||||
print("AssertionError:", err)
|
print("AssertionError:", err)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
char_count = len(msg)
|
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
|
# filter() https://docs.python.org/3.10/library/functions.html#filter
|
||||||
upper_count = len(list(filter(str.isupper, msg)))
|
upper_count = len(list(filter(str.isupper, msg)))
|
||||||
print(upper_count, "upper letters")
|
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())
|
lower_count = sum(1 for char in msg if char.islower())
|
||||||
print(lower_count, "lower letters")
|
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)
|
punctuation_count = sum(1 for char in msg if char in punctuation)
|
||||||
print(punctuation_count, "punctuation marks")
|
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")
|
space_count = msg.count(" ") + msg.count("\n")
|
||||||
print(space_count, "spaces")
|
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()])
|
digits_count = len([char for char in msg if char.isdigit()])
|
||||||
print(digits_count, "digits")
|
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)
|
Return an iterator yielding those items of iterable for which function(item)
|
||||||
is true. If function is None, return the items that are true."""
|
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:
|
if function is None:
|
||||||
return iter([item for item in iterable if item])
|
return iter([item for item in iterable if item])
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user