繁体   English   中英

如何对此进行编码以获得相似的输出,但以垂直线显示; 这是我的输出

[英]how do code this to get similar output, but in a vertical line; this is my output

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}

但我希望它以垂直线列出。

使用(如果需要,可以添加冒号和引号...)

for word, number in mylexicon.iteritems():
    print(word, number)

代替

print(mylexicon)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM