Skip to content

Commit e833164

Browse files
committed
Day 4: is_pangram i.e. string contains all alphabets
1 parent 36998fe commit e833164

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Write a Python function to check whether a string is pangram or not.
3+
Assume the string passed in does not have any punctuation.
4+
5+
Note:A pangram is a sentence containing every letter of the alphabet.
6+
Example:
7+
A quick brown fox jumps over the lazy dog.
8+
"""
9+
10+
11+
def is_pangram(input_str: str):
12+
alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
13+
'u', 'v', 'w', 'x', 'y', 'z']
14+
for item in input_str:
15+
if item.lower() in alphabets:
16+
alphabets.remove(item.lower())
17+
18+
if not alphabets:
19+
return "It is a Panagram"
20+
else:
21+
return "It is not Panagram"
22+
23+
24+
string = "A quick brown fox jumps over the lazy dog."
25+
print(is_pangram(string))
26+
print(is_pangram("hashim"))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import string
2+
3+
4+
def is_panagram(input_string):
5+
alphabets = string.ascii_lowercase
6+
7+
for char in alphabets:
8+
if char not in input_string.lower():
9+
return "It is not Pangram"
10+
return "It is Pangram"
11+
12+
13+
test = "A quick brown fox jumps over the lazy dog."
14+
print(is_panagram(test))
15+
print(is_panagram("hashim"))
16+
17+
18+
def is_pangram(_string):
19+
_string = _string.lower()
20+
# chr() convert digits from 97-123 to its ascii lower case character
21+
charset = [chr(i) for i in range(97, 123)]
22+
for char in charset:
23+
if char not in _string:
24+
return False
25+
return True
26+
27+
# Time Complexity - O(N)
28+
# Space Complexity - O(1)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import string
2+
3+
4+
def is_panagram(str1):
5+
# Create a set of the alphabet of the string passed
6+
alphabet = string.ascii_lowercase
7+
alpha_set = set(alphabet)
8+
9+
# Remove spaces from str1
10+
str1 = str1.replace(" ", '')
11+
12+
# Lowercase all strings and assigned back to string
13+
# Recall we assume no punctuation
14+
str1 = str1.lower()
15+
16+
# Grab all unique letters in the string as a set
17+
str1 = set(str1)
18+
print(str1)
19+
20+
# Now check that the alphabet set is same as string set
21+
return str1 == alpha_set
22+
23+
24+
test = "A quick brown fox jumps over the lazy dog"
25+
print(is_panagram(test))
26+
print(is_panagram("hashim"))

daily_challenges/day_4/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)