我一直在第9行得到一个关键词,我不能为我的生活弄清楚。
这是我的代码
numbers = (input("Enter numbers separated by spaces > "))
alist = []
alist = numbers.split()
count = {}
for word in alist:
if word not in alist:
(count[word]) = 1
else:
(count[word]) = (count[word]) + 1
print(count)
for k,v in count.item():
if v == 1:
print(k, "occurs", v, "time")
else:
print(k, "occurs", v, "times")
答案 0 :(得分:1)
word not in alist
始终为false,因为for循环遍历alist
。
替换以下行:
if word not in alist:
与
if word not in count:
顺便说一句,你不需要围绕count[word]
的括号。