1
- # Created by sarathkaul on 12/11/19
1
+ """
2
+ wiki: https://en.wikipedia.org/wiki/Pangram
3
+ """
2
4
3
5
4
6
def check_pangram (
@@ -8,10 +10,16 @@ def check_pangram(
8
10
A Pangram String contains all the alphabets at least once.
9
11
>>> check_pangram("The quick brown fox jumps over the lazy dog")
10
12
True
13
+ >>> check_pangram("Waltz, bad nymph, for quick jigs vex.")
14
+ True
15
+ >>> check_pangram("Jived fox nymph grabs quick waltz.")
16
+ True
11
17
>>> check_pangram("My name is Unknown")
12
18
False
13
19
>>> check_pangram("The quick brown fox jumps over the la_y dog")
14
20
False
21
+ >>> check_pangram()
22
+ True
15
23
"""
16
24
frequency = set ()
17
25
input_str = input_str .replace (
@@ -24,7 +32,41 @@ def check_pangram(
24
32
return True if len (frequency ) == 26 else False
25
33
26
34
27
- if __name__ == "main" :
28
- check_str = "INPUT STRING"
29
- status = check_pangram (check_str )
30
- print (f"{ check_str } is { 'not ' if status else '' } a pangram string" )
35
+ def check_pangram_faster (
36
+ input_str : str = "The quick brown fox jumps over the lazy dog" ,
37
+ ) -> bool :
38
+ """
39
+ >>> check_pangram_faster("The quick brown fox jumps over the lazy dog")
40
+ True
41
+ >>> check_pangram("Waltz, bad nymph, for quick jigs vex.")
42
+ True
43
+ >>> check_pangram("Jived fox nymph grabs quick waltz.")
44
+ True
45
+ >>> check_pangram_faster("The quick brown fox jumps over the la_y dog")
46
+ False
47
+ >>> check_pangram_faster()
48
+ True
49
+ """
50
+ flag = [False ] * 26
51
+ for char in input_str :
52
+ if char .islower ():
53
+ flag [ord (char ) - ord ("a" )] = True
54
+ return all (flag )
55
+
56
+
57
+ def benchmark () -> None :
58
+ """
59
+ Benchmark code comparing different version.
60
+ """
61
+ from timeit import timeit
62
+
63
+ setup = "from __main__ import check_pangram, check_pangram_faster"
64
+ print (timeit ("check_pangram()" , setup = setup ))
65
+ print (timeit ("check_pangram_faster()" , setup = setup ))
66
+
67
+
68
+ if __name__ == "__main__" :
69
+ import doctest
70
+
71
+ doctest .testmod ()
72
+ benchmark ()
0 commit comments