Python设置为检查字符串是否为panagram(全字母短句)

【Python设置为检查字符串是否为panagram(全字母短句)】给定一个字符串, 请检查给定的字符串是否为pangram(全字母短句)。
例子:

Input : The quick brown fox jumps over the lazy dog Output : The string is a pangramInput : geeks for geeks Output : The string is not pangram

通常的方法是使用频率表并检查是否存在所有元素。但是使用导入ascii_lowercase asc_lower我们将导入集合中所有较低的字符, 并将字符串中的所有所有字符导入另一个集合。在该函数中, 形成了两组-一组用于所有小写字母, 一组用于字符串中的字母。减去这两个集合, 如果它是一个空集合, 则该字符串是一个连字符。
以下是上述方法的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 strng = "The quick brown fox jumps over the lazy dog" if (check(strng) = = True ): print ( "The string is a pangram" ) else : print ( "The string isn't a pangram" )

输出如下:
The string is a pangram

首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。

    推荐阅读