From 333a2faceaab3947353f750e4bd63157aca00492 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 15 Apr 2021 13:16:20 +0200 Subject: [PATCH] Python: Total number of words in a sentence (#194) --- strings/python/word_count.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 strings/python/word_count.py diff --git a/strings/python/word_count.py b/strings/python/word_count.py new file mode 100644 index 00000000..b4b32613 --- /dev/null +++ b/strings/python/word_count.py @@ -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))