Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中检测字符串是否为pangram_Python - Fatal编程技术网

在Python中检测字符串是否为pangram

在Python中检测字符串是否为pangram,python,Python,这是怎么回事?它至少检查一次字符串是否包含a-z中的每个字符 import string def ispangram(str1, alphabet=string.ascii_lowercase): alphaset = set(alphabet) return alphaset <= set(str1.lower()) 我只能假设这与这里所说的词法排序有关,但仍然有点困惑 当我阅读这个问题中的链接时: 它说: 序列对象可以与具有相同属性的其他对象进行比较

这是怎么回事?它至少检查一次字符串是否包含a-z中的每个字符

import string

def ispangram(str1, alphabet=string.ascii_lowercase):  
    alphaset = set(alphabet)  
    return alphaset <= set(str1.lower()) 
我只能假设这与这里所说的词法排序有关,但仍然有点困惑

当我阅读这个问题中的链接时:

它说:

序列对象可以与具有相同属性的其他对象进行比较 序列类型。比较使用字典顺序:首先 比较前两项,如果它们不同,则确定 比较结果;如果它们相等,则下两项为 比较,依此类推,直到其中一个序列用尽。如果有两项 要比较的序列本身是相同类型的序列 词典比较是递归进行的。如果所有项目 两个序列比较相等,则认为序列相等。如果 一个序列是另一个的初始子序列,越短 序列是较小(较小)的序列。词典排序 字符串使用Unicode代码点编号对单个字符串进行排序 人物。相同序列之间比较的一些示例 类型


但我不清楚。

这是一个
设置
操作,而不是
列表
。相当于,

alphaset.issubset(set(str1.lower()))
s没有。这是在比较两个。因此,它将输入字符串转换为小写,然后使用Python的set类型将其与小写字母集进行比较


这是一种非常有用(且快速)的技术,用于比较两个列表,以查看它们的共同点/差异。

s.issubset(t)
相当于
s不知道为什么会被否决。这是正确的答案。谢谢,非常有帮助-毫不奇怪我被搞糊涂了。你读到了吗?我现在读到了,谢谢@alfasin
def pangram(s):
alphabet = set('abcdefghijklmnopqrstuvwxyz')
s = s.replace(' ','').lower()
s= sorted(s)

count = {}

    #alphabet could be one sting within '' later sorted, but I just went straight to the point. 
    #After initializing my dictionary at null, we start the count    

for letter in s:
    if letter in count:
        count[letter] =[]
    else:
        count[letter] = 1

for letter in alphabet:
    if letter in count:
        count[letter] =[]
    else:
        count[letter] = 0
for letter in count:
    if count[letter]== 0:
        print (letter +' missing!')
print (count[letter]!= 0)
def pangram(s):
alphabet = set('abcdefghijklmnopqrstuvwxyz')
s = s.replace(' ','').lower()
s= sorted(s)

count = {}

    #alphabet could be one sting within '' later sorted, but I just went straight to the point. 
    #After initializing my dictionary at null, we start the count    

for letter in s:
    if letter in count:
        count[letter] =[]
    else:
        count[letter] = 1

for letter in alphabet:
    if letter in count:
        count[letter] =[]
    else:
        count[letter] = 0
for letter in count:
    if count[letter]== 0:
        print (letter +' missing!')
print (count[letter]!= 0)