def main():
myfile = input("Please enter a File: ")
open_file = open(myfile, "r")
mylexicon = {}
mytext = open_file.readlines()
acc = 0
for line in mytext:
words = line.split()
for word in words:
if word not in mylexicon:
mylexicon[word] = 1
else:
mylexicon[word] = mylexicon[word] + 1
mylexicon = mylexicon.readline()
print(mylexicon)
main()
上面的代码生成输出:
{'mouse': 2, 'last': 1, 'and': 1, 'jumped': 1, 'over': 1, 'Zippy': 1, 'the': 2, 'cat': 3, '1': 1, '2': 1}
但我想把它列在一条垂直线上
使用(如果愿意,可以添加冒号和引号…)
而不是
相关问题 更多 >
编程相关推荐