Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x Python 3.3字典_Python 3.x - Fatal编程技术网

Python 3.x Python 3.3字典

Python 3.x Python 3.3字典,python-3.x,Python 3.x,这段代码告诉我如何确定单词dog出现在我的列表中的次数。 但是,如何确定“是”和“否”两个词是否同时出现在我的列表中 我用这个来理解一个更大的列表,其中需要确定年龄和位置等因素,但我从两个小列表开始,这样我才能理解。对python来说完全是陌生的 代码的第一行 myfile = ["no", "yes", "dog", "dog", "dog", "male"], ["no", "orange", "symbol", "church"] my_Male_Dict = {} for word

这段代码告诉我如何确定单词dog出现在我的列表中的次数。 但是,如何确定“是”和“否”两个词是否同时出现在我的列表中


我用这个来理解一个更大的列表,其中需要确定年龄和位置等因素,但我从两个小列表开始,这样我才能理解。对python来说完全是陌生的

代码的第一行

myfile = ["no", "yes", "dog", "dog", "dog", "male"], ["no", "orange", "symbol", "church"]


my_Male_Dict = {}
for word in myfile:
    if word in my_Male_Dict:
       my_Male_Dict[word] += 1
    else:
        my_Male_Dict [word] = 1
print (my_Male_Dict['dog'])
实际上,由于两个列表之间的逗号,将
myfile
指向一个列表元组;当您遍历它时,每个
单词都将是一个列表

如果您想知道某个单词是否出现在您创建的词典中,只需使用

myfile = ["no", "yes", "dog", "dog", "dog", "male"], ["no", "orange", "symbol", "church"]

它将检查字典的键,并返回是否包含
word
(您也可以在列表中检查
word
)。

您能举例说明它应该是什么样子吗?想要的打印输出是什么?您好,基本上我想要一个数字,1、2或3作为它出现的时间。谢谢
word in myDict