给定一个字符串,检查给定的字符串是否为pangram。 例如:
null
Input : The quick brown fox jumps over the lazy dogOutput : The string is a pangramInput : geeks for geeksOutput : The string is not pangram
通常的方法是使用频率表,检查是否所有元素都存在。但是使用 将ascii_小写输入为asc_小写 我们将集合中的所有低位字符和字符串中的所有字符导入另一个集合。在函数中,形成两个集合——一个用于所有小写字母,另一个用于字符串中的字母。这两个集合相减,如果它是一个空集,字符串就是一个pangram。 下面是上述方法的Python实现:
python
# import from string all ascii_lowercase and asc_lower from string import ascii_lowercase as asc_lower # function to check if all elements are present or not def check(s): return set (asc_lower) - set (s.lower()) = = set ([]) # driver code string = "The quick brown fox jumps over the lazy dog" if (check(string) = = True ): print ( "The string is a pangram" ) else : print ( "The string isn't a pangram" ) |
输出:
The string is a pangram
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END