Python: Total number of words in a sentence (#194)

pull/205/head
Christian Clauss 2021-04-15 13:16:20 +02:00 committed by GitHub
parent 8d5cae05ff
commit 333a2facea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,10 @@
def word_count(s: str) -> int:
return len(s.lower().split())
def unique_word_count(s: str) -> int:
return len(set(s.lower().split()))
for s in ("The Matrix", "To Be or Not to Be", "Kiss Kiss Bang Bang"):
print(s, word_count(s), unique_word_count(s))