def calc (allWords):
d = {}
for word in allWords:
if word in d.keys():
d[word] = d[word] + 1
else:
d[word] = 1
print (word , d[word])
def retriveFile():
FileObject = open ("a.txt")
data = FileObject.read()
abc = data.split()
calc(abc)
return abc
retriveFile()
我正在尝试使用类将字典转换为2个对象的列表
第一个对象必须有实例变量(字符串) 第二个对象必须有字数(int)
我似乎不明白怎样才能在课堂上工作,但我是这样开始的:
class list:
def __init__(self, words, antal):
self.words = words
self.antal = antal
for words, antal in d.items()
if words
我不是100%确定我理解,但我想你想要一个Counter
相关问题 更多 >
编程相关推荐