diff --git a/README.md b/README.md index 79c1d0808..f2adbaadf 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,7 @@ If you want to uninstall algorithms, it is as simple as: - [judge_circle](algorithms/strings/judge_circle.py) - [strong_password](algorithms/strings/strong_password.py) - [caesar_cipher](algorithms/strings/caesar_cipher.py) + - [check_pangram](algorithms/strings/check_pangram.py - [contain_string](algorithms/strings/contain_string.py) - [count_binary_substring](algorithms/strings/count_binary_substring.py) - [repeat_string](algorithms/strings/repeat_string.py) diff --git a/algorithms/strings/__init__.py b/algorithms/strings/__init__.py index 72ea7d70d..37c83dfdd 100644 --- a/algorithms/strings/__init__.py +++ b/algorithms/strings/__init__.py @@ -25,6 +25,7 @@ from .judge_circle import * from .strong_password import * from .caesar_cipher import * +from .check_pangram import * from .contain_string import * from .count_binary_substring import * from .repeat_string import * diff --git a/algorithms/strings/check_pangram.py b/algorithms/strings/check_pangram.py new file mode 100644 index 000000000..412425793 --- /dev/null +++ b/algorithms/strings/check_pangram.py @@ -0,0 +1,10 @@ +""" +Algorithm that checks if a given string is a pangram or not +""" + +def check_pangram(input_string): + alphabet = "abcdefghijklmnopqrstuvwxyz" + for ch in alphabet: + if ch not in input_string.lower(): + return False + return True \ No newline at end of file diff --git a/tests/test_strings.py b/tests/test_strings.py index b8750b1f8..5544086fa 100644 --- a/tests/test_strings.py +++ b/tests/test_strings.py @@ -28,6 +28,7 @@ judge_circle, strong_password, caesar_cipher, + check_pangram, contain_string, count_binary_substring, repeat_string, @@ -454,6 +455,11 @@ def test_caesar_cipher(self): self.assertEqual("Lipps_Asvph!", caesar_cipher("Hello_World!", 4)) self.assertEqual("okffng-Qwvb", caesar_cipher("middle-Outz", 2)) +class TestCheckPangram(unittest.TestCase): + def test_check_pangram(self): + self.assertTrue(check_pangram("The quick brown fox jumps over the lazy dog")) + self.assertFalse(check_pangram("The quick brown fox")) + class TestContainString(unittest.TestCase): def test_contain_string(self):